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
>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