Group: microsoft.public.word.vba.general
From: =?Utf-8?B?QXNzb2NpYXRlcw==?=
Date: Monday, March 31, 2008 12:43 AM
Subject: Re: how to track which section it's at

Hi Jay,

Thank you for your reply.

Sorry i think you have misunderstood my question. What i mean is when user
would like to add a picture, he/she would press button "insert picture" . The
"insert picture"
dialog box shows up and add the pic to the document. Not only that, it would
also add a label below the picture (label such as Figure 1.1 or 2.1 followed
by text)

Figure "1" or "2" depends on the Sections number. If the picture is placed
under Section 1, then it'd be Figure 1.1. If it's Section 3, it'd be Figure
3.1. So i'm not hard-coding the number in the figure but rather using codes
to track which Section it's at and print it on the report.

Hope my explanation helps you to understand my situation.

Thank you in advance

"Jay Freedman" wrote:

> You've got a bad case of reinventing the wheel here. Instead of trying to
> hard-code the section number, insert a {SECTION} field.
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
> may benefit.
>
> On Sun, 30 Mar 2008 18:01:02 -0700, Associates
> wrote:
>
> >Hi,
> >
> >I have a question i need to ask of you in regards to word 03. In the report
> >word document, I have a button called "insert picture". What it does is it
> >will bring up the insert picture windows dialog box and then prompt user for
> >the text message for the picture.
> >
> >for example,
> >
> >somewhere in the word report, we have something like as follows
> >
> >Section 2. Light Bulb Prices
> >
> >some texts ........................
> >
> > picture
> > Figure 2.1 List of Light Bulb prices
> >
> >some texts ........................
> >
> >
> >The number "2" in the Figure comes from the Section number. If the Section
> >is 3, then it should show Figure 3.1
> >Section 2 - this section is generated by Bullets and Numbering.
> >
> >My question here is how do i know which Section it is now at?
> >
> >I have the following code but it gives the wrong answer. The answer should
> >be 2 but it says 8 (which i think, is the page number)
> >
> >Sub InsertPicture()
> >
> > Dim srange As Range
> > Dim ssection As Section
> > Dim i As Long
> > i = Selection.Information(wdActiveEndSectionNumber)
> >
> > Set srange = Selection.Sections(1).Range
> >
> > srange.Collapse wdCollapseEnd
> >
> > Set srange = ActiveDocument.Sections(i + 1).Range
> > srange.Collapse wdCollapseStart
> >
> > Selection.TypeParagraph
> > Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
> >
> > Dialogs(wdDialogInsertPicture).Show
> >
> > Selection.TypeParagraph
> >
> > Selection.TypeText ("Figure " &
> >srange.Information(wdActiveEndSectionNumber) & "." & pictureCounter & " - " &
> >pictureText)
> > Selection.TypeParagraph
> > Selection.TypeParagraph
> > Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
> >
> >End Sub
> >
> >Thank you in advance
>