PDA

View Full Version : [SOLVED:] GoTo Next Issue



heedaf
07-13-2017, 12:33 PM
I'm using the following code:


Set R1 = ActiveDocument.GoTo(What:=wdGoToHeading, Which:=wdGoToFirst)
R1.Expand Unit:=wdCharacter
Set R1 = ActiveDocument.GoTo(What:=wdGoToHeading, Which:=wdGoToNext)
R1.Expand Unit:=wdCharacter

It will find the first heading but it won't go to the next heading. Anyone have any idea what the problem is?

gmaxey
07-13-2017, 12:56 PM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 7/13/2017
Dim R1
Set R1 = ActiveDocument.GoTo(What:=wdGoToHeading, Which:=wdGoToFirst)
R1.Expand Unit:=wdCharacter
'R1.Select
Set R1 = ActiveDocument.GoTo(What:=wdGoToHeading, Which:=wdGoToNext)
R1.Expand Unit:=wdCharacter
R1.Select
lbl_Exit:
Exit Sub
End Sub

heedaf
07-13-2017, 01:03 PM
Thank you for the reply but it still stays on the first Heading.

gmaxey
07-13-2017, 01:04 PM
Attach the document.



Sub FirstHeading()
Selection.GoTo What:=wdGoToHeading, Which:=wdGoToFirst
End Sub
Sub NextHeading()
Application.Browser.Target = wdBrowseHeading
Application.Browser.Next
End Sub

heedaf
07-13-2017, 01:20 PM
I kind of figured out what the problem is. We are converting a document from an antiquated program called QuickSilver and it converts the headings to a "section:#". When I changed "Section 1" to Heading 1 it worked ok. So I'm confused why it found the first "Section: 1" but wouldn't go to the next "Section: 1". Any idea why? Is there a goto "what" that would work on this kind of style?

gmaxey
07-13-2017, 01:25 PM
You could find all of the section: # instances and apply a heading style to them. To use your own advice, if you are using office products there is practically nothing you can't do, you just have to write the code.

heedaf
07-13-2017, 01:34 PM
What is weird is that it is listed as a heading style already. That is why I was confused.