Consulting

Results 1 to 15 of 15

Thread: Activate Web Addresses as Hyperlinks in Word

  1. #1

    Activate Web Addresses as Hyperlinks in Word

    Hi,

    I want a button or some macro to allow the user to activate the hypertext that's been inserted by autotext. I already created the template to add the grammar hyperlinks, and now I just need an instruction that will turn on the links.

    This is a template for teachers to use in students' papers in a program called Office Hours. This program allows participants to share applications in real time.

    Thanks!

    Jim Musgrave

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Can you post the template for me to work with?

  3. #3
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Hi, Jim! Glad to see you made it.

    We should build Jim a toolbar, using VBA, with just one button on it. When clicked, it should find all instances of text beginning with http:// and make it a hyperlink. The only problem I have in doing this macro myself is that the hyperlink could be followed by a space or a period, I'm sure, neither of which should be part of the hyperlink address. Also, we don't need to hide the address or anything; just make it an active hyperlink using the same address.

    Oh...if somebody can give me the code for the hyperlinks, I can build the toolbar.

    Jim: You might want to consider adding your autotext entries to the toolbar, which would ideally float. If you'd like to do that, let us know.
    ~Anne Troy

  4. #4

    Hyperlinks copied?

    Is it possible to (easily) copy the hypertext links to the program you're suggesting?

  5. #5
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    We wouldn't even need to, Jim. I would assign buttons for each one. Behind each button, we'd put a macro. Behind each macro, we'd put one of your autotext entries. The bother would be that if you wanted to add a new hyperlink, you'd have to code it to add it to the toolbar.

    However, I would be that our Jake (DRJ) could probably make that hyperlink macro button for you, put it on a toolbar, and then add all the autotext entries as a dropdown to it. My only gripe on that would be that I wouldn't wanna see all Word's default autotext in it, would you? In which case, we'd want to do the macro thing.

    Now, if you're reasonably intelligent, and I think you are, you could easily add an autotext, and edit the toolbar and other VBA code to add a new entry to the toolbar. But that's up to you.

    There's a really good example here: http://www.vbaexpress.com/kb/getarticle.php?kb_id=14 The only difference would be that those "subs" you see that insert letter closings would be autotext entries instead.

    I did something VERY similar here: http://www.vbaexpress.com/forum/showthread.php?t=877

    Only his autotext entries included graphics.
    You might want to download his file, though, since it'd pretty much show what I mean.
    ~Anne Troy

  6. #6
    Yes, I certainly could make-out the logic and add my own hypertext. That's how I learned .html!

    Thanks, this sounds awesome.

  7. #7
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Please attach a zip file with an example of your data so that I can see what we are working with.

  8. #8
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    We didn't mention that Jim first wanted to be able to use Autotext entries, but he didn't want the formatting copied over because they're being inserted into "anyone's" files, and the formatting is unknown. So, we already gave him a macro (off VBAX and I can't share the macro) that automatically makes autotext entries "unformatted text". That means that it takes on the formatting at the insertion point. Now, when we do that, Jim loses his active hyperlinks. With this macro, we're putting them back.

    Winzip and then upload (attach) the file you sent me, Jim. Or I can do it if you can't figure it out. To attach a file, you gotta hit the "Go Advanced" button below the reply box.
    ~Anne Troy

  9. #9
    Any progress on this yet?

    Thanks,

    Jim

  10. #10
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    I'm not good with autotext so I don't totally understand the requirement but this code will find all text beginning "http://" and ending either space or paragraph mark. It then drops the last character and if the (new) last character is a dot it drops that as well and then converts the remains to a hyperlink. The list of trailing delimiters can easily be added to, to include, say, manual line breaks or tabs or whatever you want/use.

    It's a bit rough and ready, but is this what you're after?

    [VBA] Selection.HomeKey wdStory

    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = "http://*[ ^13]"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With

    While Selection.Find.Execute
    Selection.MoveEnd wdCharacter, -1
    If Right(Selection, 1) = "." Then Selection.MoveEnd wdCharacter, -1
    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
    Address:=Selection.Range.Text
    Selection.Collapse wdCollapseEnd
    Wend[/VBA]
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  11. #11
    How do I insert this in the document template?

  12. #12
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Copy the code above.
    Open the template.
    Hit Alt+F11 to access the visual basic editor (VBE).
    On the top-left, choose your template's name and then hit Insert-Module.
    On the right, type:

    [vba]
    Option Explicit
    Sub GetHTTP()
    [/vba]
    Paste the code into the code window that appears at right of your screen.
    Then type:
    [vba]
    End Sub
    [/vba]

    Close the VBE.
    To test: Tools-Macro-Macros and double-click GetHTTP.

    If it works, assign a toolbar button to the macro. To do that, begin with step 2 at:
    http://theofficeexperts.com/officevba.htm#WordVBA

    ~Anne Troy

  13. #13
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    This might be too much detail - I don't know what you know.

    In Word, Alt+F11 to open the VBE
    In the VBE, Ctrl+r to open the Project Explorer (if not open)
    In the Project Explorer locate your Template and right click on it
    Select Insert > Module
    In the Code Window which opens, Enter Sub MakeHyperlinksFromText and Press Enter
    It will add an End Sub line for you
    Between the Sub and End SUb, cut and paste the code
    Alt+F4 (or whatever) to close the VBE

    To run:

    In Word, Alt+F8
    Find MakeHyperlinksFromText in the list and double click it.

    If it does what you want we can move on to setting up buttons.

    Anne types faster than me - she also distracts me with PMs while she's doing it.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  14. #14
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Quote Originally Posted by TonyJollans
    Anne types faster than me - she also distracts me with PMs while she's doing it.
    ROFL!! :rofl

    Get back to coding. I'll take care of your lightwork.
    ~Anne Troy

  15. #15
    VBAX Regular
    Joined
    Sep 2008
    Posts
    39
    Location
    LOL!!

Posting Permissions

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