News, tips, advice, support for Windows, Office, PCs & more. Tech help. No bull. We're community supported by donations from our Plus Members, and proud of it
Home icon Home icon Home icon Email icon RSS icon
  • Adding n Switch To Hyperlinks

    Posted on WShuntnyc Comment on the AskWoody Lounge
    Viewing 1 reply thread
    • Author
      Posts
      • #351907 Reply
        WShuntnyc
        AskWoody Lounger

        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

      • #510512 Reply
        Andrew Lockton
        AskWoody_MVP

        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 Reply
          WShuntnyc
          AskWoody Lounger

          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 Reply
            WSGary Frieder
            AskWoody Lounger

            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 Reply
              WShuntnyc
              AskWoody Lounger

              Gary,

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

              Regards,

              Gary

              • #510602 Reply
                WSGary Frieder
                AskWoody Lounger

                Hi again,

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

              • #510653 Reply
                Andrew Lockton
                AskWoody_MVP

                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 Reply
                WSGary Frieder
                AskWoody Lounger

                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 Reply
                WShuntnyc
                AskWoody Lounger

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

                Gary

    Viewing 1 reply thread

    Please follow the -Lounge Rules- no personal attacks, no swearing, and politics/religion are relegated to the Rants forum.

    Reply To: Adding n Switch To Hyperlinks

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