• Adding n Switch To Hyperlinks

    Author
    Topic
    #351907

    After reading a tip concerning how to keep documents from which you click a
    hyperlink open after link is clicked, I want to add the n switch to all the
    hyperlinks in my Word 97 document. Further, if possible, I wanted to create
    another macro where when I add a hyperlink I could have a YesNo messagebox
    appear asking if I wanted the linked object to open in a new window or not.
    If answered yes, the n switch would be added.

    Your help on these would be greatly appreciated. I have modified the Mark
    TOC command with the option of adding the n switch but I cannot figure out
    how I can display the Insert Hyperlink dialog. Thanks again for your help
    on these two pieces of code.

    Regards,

    Gary

    Viewing 0 reply threads
    Author
    Replies
    • #510512

      Gary

      To make sure all the hyperlinks in the document have the n switch you could run

        ActiveWindow.View.ShowFieldCodes = True
        With Selection.Find
          .ClearFormatting
          .Replacement.ClearFormatting
          .Text = "HYPERLINK "
          .Replacement.Text = "HYPERLINK n "
          .Forward = True
          .Wrap = wdFindAsk
          .Format = False
          .MatchCase = True
          .MatchWholeWord = False
          .MatchWildcards = False
          .MatchSoundsLike = False
          .MatchAllWordForms = False
          .Execute Replace:=wdReplaceAll
        End With
        ActiveWindow.View.ShowFieldCodes = False
      

      I am stumped on displaying the InsertHyperlink Dialog though. I can’t find it in my set of available dialogs in Word 97. If you have Word 2000 you could try the following (sorely missed) Robin Trew code which might show the way.
      There are a couple of quirks to be aware of:

      The first time you run the macro, it sometimes generates a list of just 9 dialogs and then stops. Simply run it again.
      Half-way through, it may mysteriously pop a “Choose Profile” dialog on to the screen. Simply tap ESC and let it continue.
      It is not always very fast, allow it a little time to finish.

      Sub ListWd9Dialogs()
         
          Dim dlgs As Word.Dialogs
          Dim dlg As Word.Dialog
          Dim docList As Word.Document
          
          Dim strReport As String
          Dim i As Long
          
          Set dlgs = Word.Dialogs
              
              For Each dlg In dlgs
                  i = i + 1
                  strReport = strReport & CStr(dlg.Type) & _
                              vbTab & dlg.CommandName & vbCr
              Next
          Set dlgs = Nothing
          strReport = strReport & vbCr & "Total: " & CStr(i)
          
          Set docList = Documents.Add
          With docList
              .Range.Text = strReport
              .Activate
          End With
          Exit Sub
      Problem:
          Debug.Print CStr(i); "PROBLEM "; Err.Description
          Err.Clear
          Resume Next
      End Sub
      • #510515

        Andrew,

        Thanks for the effort. I will use this to at least change the hyperlinks in my documents but I too discovered you cannot access the dialog for Hperlinks. I am using Word 97 also.

        Thanks agian. If anyone else knows how to get to the dialog, please let us know.

        Regards,

        Gary

        • #510551

          Hi Gary,

          As a “cheat”, you could use:

          SendKeys “^k”

          which is probably safe enough.

          Andrew, thanks for posting that R.Trew code – I think that’s (BOOL) (Best Of the Old Lounge) posting #1.

          Gary

          • #510565

            Gary,

            Thanks, but that does not work for me when I try it. Does it work for anyone else?

            Regards,

            Gary

            • #510602

              Hi again,

              Here’s a quick test: when you use the key combination Control+k, does your Insert Hyperlinks dialog open?

            • #510653

              Gary (F)

              Do you remember the code we posted on ye olde lounge to activate a menu item we couldn’t call the right way? I posted one using numbers and you came up with a constant name that was a more bullet-proof. I reckon that same code would do the job here but I can’t remember it or find it or remember it (and I’ll tell you another thing – my memory’s not real good either).

              Gary H may have reassigned his Control-K, I know I have.

            • #512558

              Hi Andrew and Gary H.,

              It took me a couple of weeks to remember (slow search time, huh?), but here’s something like the code that was posted on the OL:

              Sub ShowHLinksDialog()
              CommandBars(1).Controls(“Hyper&link…”).Execute
              End Sub

              It appears that the Menu Bar is always number 1 in the CommandBars collection, so this will run no matter the location of the Menu Bar. With the other toolbars, very likely something like:
              CommandBars(“Standard”). etc.
              would work too.

              Gary F.

            • #510679

              Yes, Gary, that does work! But, the sendkeys does not.

              Gary

    Viewing 0 reply threads
    Reply To: Adding n Switch To Hyperlinks

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: