Consulting

Results 1 to 7 of 7

Thread: GoTo Next Issue

  1. #1
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location

    GoTo Next Issue

    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?

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    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
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    Thank you for the reply but it still stays on the first Heading.

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    Attach the document.

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

    Visit my website: http://gregmaxey.com

  5. #5
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    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?

  6. #6
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    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.
    Greg

    Visit my website: http://gregmaxey.com

  7. #7
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    What is weird is that it is listed as a heading style already. That is why I was confused.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •