Results 1 to 9 of 9
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding \n Switch To Hyperlinks

    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

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Adding \n Switch To Hyperlinks

    Gary

    To make sure all the hyperlinks in the document have the n switch you could run
    <pre> 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
    </pre>


    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.


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

    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    Star Lounger
    Join Date
    Jan 2001
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding \n Switch To Hyperlinks

    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

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Adding \n Switch To Hyperlinks

    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

  5. #5
    Star Lounger
    Join Date
    Jan 2001
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding \n Switch To Hyperlinks

    Gary,

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

    Regards,

    Gary

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Adding \n Switch To Hyperlinks

    Hi again,

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

  7. #7
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Adding \n Switch To Hyperlinks

    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.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  8. #8
    Star Lounger
    Join Date
    Jan 2001
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding \n Switch To Hyperlinks

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

    Gary

  9. #9
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Adding \n Switch To Hyperlinks

    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.

Posting Permissions

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