Create hyperlink via macro? Word 2007

Having a problem creating a macro to insert a hyperlink in Word 2007. Here's 
exactly what I want it to do:

1. AFTER I highlight a few words or so in the document, I press the 
button/hotkeys that kicks off the macro
2. The Insert Hyperlink box comes up
3. The address bar gets prefilled with EXACTLY the same text (a lengthy, 
unchanging path to a file) EVERY TIME, then the macro STOPS or PAUSES running 
so that the user can enter a specific file name, which will change each time, 
thus completing the full path.
4. I click on OK and the hyperlink is created correctly.
5. We only see the clickable text in the document, as a link to the fully 
qualified file name as entered, NOT the actual hyperlink code.

The problem:

When I recorded the macro initially, I typed in the path string uneventfully 
but there's no way to stop or pause the recording at this point, because it's 
in a dialog box. If I let it finish, because it never paused to let me enter 
a file name, there's not one in the resulting hyperlink. In addition, because 
it also captured the highlighted text, even tho it was highlighted before 
starting to record, running this macro a second time replaces the new 
highlighted text with the highlighted text from the previous hyperlink.

I believe that with judicious editing of the macro in VBA maybe this can all 
be done, but I'm simply not familiar enough with the code to do that. This is 
the code it generated:

Sub HyperlinkPath()
' HyperlinkPath Macro
    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
        
"http://www.albemarle.org/upload/images/forms_center/board_of_supervisors/forms/agenda/2010files/" _
        , SubAddress:="", ScreenTip:="", TextToDisplay:= _
        "First Highlighted Text"

Is this even doable? If so, can someone point me to a solution?

TIA

elaine
charlottesville, va
0
Utf
3/17/2010 4:24:01 PM
word.docmanagement 5542 articles. 2 followers. Follow

2 Replies
2426 Views

Similar Articles

[PageSpeed] 3

Use the following macro. Besides using the current selected text as the 
hyperlink's display text, it also does some error checking to make sure the 
selection is valid and that the user has entered something in the input box. 
The underscores at the ends of some lines indicate that the statement 
continues on the next line; the space before the underline is required.

Sub HyperlinkPath()
    Const Path = "http://www.albemarle.org/upload/images/" & _
        "forms_center/board_of_supervisors/forms/agenda/2010files/"
    Dim displayText As String
    Dim addressText As String
    Dim fileName As String

    If Selection.Type <> wdSelectionNormal Then
        MsgBox prompt:="Please select some text.", _
            buttons:=vbOKOnly + vbCritical, Title:="Invalid Selection"
        Exit Sub
    End If

    fileName = InputBox("Enter file name:", "Hyperlink Path")
    If Len(fileName) = 0 Then Exit Sub 'canceled or didn't enter anything

    addressText = Path & fileName
    displayText = Selection.Text

    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
        Address:=addressText, TextToDisplay:=displayText
End Sub


-- 
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so 
all may benefit.

EPPack wrote:
> Having a problem creating a macro to insert a hyperlink in Word 2007.
> Here's
> exactly what I want it to do:
>
> 1. AFTER I highlight a few words or so in the document, I press the
> button/hotkeys that kicks off the macro
> 2. The Insert Hyperlink box comes up
> 3. The address bar gets prefilled with EXACTLY the same text (a
> lengthy,
> unchanging path to a file) EVERY TIME, then the macro STOPS or PAUSES
> running
> so that the user can enter a specific file name, which will change
> each time,
> thus completing the full path.
> 4. I click on OK and the hyperlink is created correctly.
> 5. We only see the clickable text in the document, as a link to the
> fully
> qualified file name as entered, NOT the actual hyperlink code.
>
> The problem:
>
> When I recorded the macro initially, I typed in the path string
> uneventfully
> but there's no way to stop or pause the recording at this point,
> because it's
> in a dialog box. If I let it finish, because it never paused to let
> me enter
> a file name, there's not one in the resulting hyperlink. In addition,
> because
> it also captured the highlighted text, even tho it was highlighted
> before
> starting to record, running this macro a second time replaces the new
> highlighted text with the highlighted text from the previous
> hyperlink.
>
> I believe that with judicious editing of the macro in VBA maybe this
> can all
> be done, but I'm simply not familiar enough with the code to do that.
> This is
> the code it generated:
>
> Sub HyperlinkPath()
> ' HyperlinkPath Macro
>    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
>
> "http://www.albemarle.org/upload/images/forms_center/board_of_supervisors/forms/agenda/2010files/"
>        _ , SubAddress:="", ScreenTip:="", TextToDisplay:= _
>        "First Highlighted Text"
>
> Is this even doable? If so, can someone point me to a solution?
>
> TIA
>
> elaine
> charlottesville, va 


0
Jay
3/17/2010 8:02:18 PM
Hi Elaine,

The following revised version of your macro works for me.

Sub HyperlinkPath()
    ' HyperlinkPath Macro
    
    Dim UrlPath As String
    Dim FileName As String
    
    UrlPath = "http://www.albemarle.org/upload/images/" _
        & "forms_center/board_of_supervisors/forms/agenda/2010files/"
    FileName = InputBox("Type the file name.", "File Name")
    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
        Address:=UrlPath & FileName
End Sub

-- 
Hope this helps,
Pesach Shelnitz
My Web site: http://makeofficework.com 


"EPPack" wrote:

> Having a problem creating a macro to insert a hyperlink in Word 2007. Here's 
> exactly what I want it to do:
> 
> 1. AFTER I highlight a few words or so in the document, I press the 
> button/hotkeys that kicks off the macro
> 2. The Insert Hyperlink box comes up
> 3. The address bar gets prefilled with EXACTLY the same text (a lengthy, 
> unchanging path to a file) EVERY TIME, then the macro STOPS or PAUSES running 
> so that the user can enter a specific file name, which will change each time, 
> thus completing the full path.
> 4. I click on OK and the hyperlink is created correctly.
> 5. We only see the clickable text in the document, as a link to the fully 
> qualified file name as entered, NOT the actual hyperlink code.
> 
> The problem:
> 
> When I recorded the macro initially, I typed in the path string uneventfully 
> but there's no way to stop or pause the recording at this point, because it's 
> in a dialog box. If I let it finish, because it never paused to let me enter 
> a file name, there's not one in the resulting hyperlink. In addition, because 
> it also captured the highlighted text, even tho it was highlighted before 
> starting to record, running this macro a second time replaces the new 
> highlighted text with the highlighted text from the previous hyperlink.
> 
> I believe that with judicious editing of the macro in VBA maybe this can all 
> be done, but I'm simply not familiar enough with the code to do that. This is 
> the code it generated:
> 
> Sub HyperlinkPath()
> ' HyperlinkPath Macro
>     ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
>         
> "http://www.albemarle.org/upload/images/forms_center/board_of_supervisors/forms/agenda/2010files/" _
>         , SubAddress:="", ScreenTip:="", TextToDisplay:= _
>         "First Highlighted Text"
> 
> Is this even doable? If so, can someone point me to a solution?
> 
> TIA
> 
> elaine
> charlottesville, va
0
Utf
3/17/2010 8:08:04 PM
Reply:

Similar Artilces:

Help with macro #6
Good evening: Is it possible to insert a formula in the below listed MACRO. [Column D is always a date. I need Column F to display a date 14 days greater] Thanks in advance John Sub EnterGrievance() ' ' EnterGrievance Macro ' Macro recorded 2/25/2008 by John Donadio ' ' Keyboard Shortcut: Ctrl+c 'Range("A12").Select Dim FromRng As Range Dim ToRng As Range With Worksheets("Data Sheet") Set FromRng = .Range("A12:M12") End With With Worksheets("Grievance Log") Set ToRn...

create a roster
How can you create a weekly roster in which functions can be assigned to more than 10 people. The roster should be updatable, so that when holidays and days off are marked on the weekly roster they will be taken account of it future rosters. ...

2003 to 2007 02-25-08
I created a db on home computer in v. 2003. Works fine opening it in 2003 on computer at work. Then try to work with it in 2007 and every time I try to see anything in Design view I get this error: The command or action 'OpenTable' isn't available now. *You may be in a read-only database or an unconverted databse from an earlier version of MS Access. *The type of object the action applies to isn't currently selected or isn't in the active view. Use only those commands and macro actions that are currently available for this database. I've tried: ...

macro problem with Word 2001
Whenever I attach a Word 2001 document to an email and send it to someone using PC, the PC user's computer interprets the macros as a virus. How can I a) disable macros on Word or b) send it in a way that the PC will not interpret it as a virus? Thanks for any help Hi Unless you are intentionally making Word documents with Macros it is almost certain that you are indeed sending documents that have a virus. If your Word documents are supposed to have macros, then your audience needs to adjust the security settings on their computer in Word (Tools > Options > Security > Ma...

importing or creating reference footnotes
I am trying to import a word document into publisher and it has reference footnotes within the document. The reference footnotes are not coming into the publisher document with the reference footnotes. Correct, they will not up to Publisher 2003. In Publisher 2003 depending on which version of Word you are using if they will or not. -- "If you don't know where you are going, any road will take you there!" ...

Unwanted Hyperlink
When sending email, all URLs are doubled and "HYPERLINK" is added in front of the link. Cannot find how to stop this. Help appreciated ...

Mailbox not created when AD account created
A couple of days ago I noticed that I created a user account but the 'Email Addresses' tab of the user properies did not list any email addresses. Subsequent new user accounts have all experienced the same. I researched the knowledge and tried the recommended solutions to either manaully start the recipient update service or rebuild te recipient update service. Neither recommendation has resulted in a mailbox being created for this particular user or any additional user that I have created since this error first showed up. I performed a Windows update last Thursday and so I bel...

Task Create - Status
I'm trying to make a simple task, when a user owner is assigned a task in CRM, it receives an email letting it know it has one. I have the following below, but it is not generating one when i assign one manually in the CRM. What to do? I've tried both the following: When task is created E-Mail to:[owner];Subject test As well as: When task is created if Task activity status = Open then E-Mail to:[owner];Subject test I've checked the mailserver many times over, and I can send emails manually from the CRM so you can rule that out Tested out ok on our end. Some ideas:...

2007 pst files
I just installed the 2007 update of Office. Everything installed fine, however I can't open Outlook. The error message says there are errors in my Personal Folders.pst. and to use Scanpst.exe to repair it. I can't find the file. I did a search and also looked in the Program Files\Common Files\System\MSMAPI\1033 folder - it's not there. How do I get the file and will this work with 2007? Thanks jan it should be located at following.. drive:\Program Files\Microsoft Office\OFFICE12. -- Laura Rooke MVP - Mobile Devices wiersma7, you wrote on Wed, 13 Jun 2007 19:49:20 ...

Help Creating XmlNode / XmlAttribute Elegantly
I am creating a configuration class to read / write a standard configuration file. <?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="ConnectionString" value="server=(local);" /> </appSettings> </configuration> I am using a XmlDocument for my base implementation. I am looking to see if there is a better way to add a new node / attribute than using XmlDocument.InnerXml. I would consider this to be a hack but couldn't really see another way of doing this without definin...

Create external database
Hi all. I need to create an external database (file). On a site I found this code: ------------------------------------------------------ Function CreateLinkedExternalTable(strTargetDB As String, strProviderString As String, strSourceTbl As String, strLinkTblName As String) As String 'strTargetDB = Source Database Name 'strProviderString = Not used, currently hard coded 'strSourceTbl = Source Table name in the database we are linking too. 'strLinkTblName = Table name we would like to see in the Access Database. Dim catDB As ADOX.Catalog Dim tblLink As...

Convert two separate Word documents into one
Anybody know how to merge/convert two separate (one page) Word document into one (two page) document? HELP> In news:B5526982-84F0-4552-A34F-7F72AB3DADDC@microsoft.com, CAOWEN <CAOWEN@discussions.microsoft.com> typed: > Anybody know how to merge/convert two separate (one page) Word > document into one (two page) document? > > HELP> Open one of them. PUt the cursor at the very bottom (CTRL-END keys works well for that). Click Insert File. Save the resulting combined file to a NEW NAME to avoid losing either of the two originals. HTH, Twayne ...

Why can't I see clipart on word or publisher.
I have just bought a new desktop computer and loaded microsoft office 2003. When i insert clipart onto a page in publisher or word, I cannot see the picture. the handles are on the page put picture isn't what can I do? Read the third FAQ here Q: Why can I not see images/shapes/lines when editing my publication? http://ed.mvps.org/Static.aspx?=Publisher/FAQs -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com http://officebeta.iponet.net/en-us/publisher/FX100649111033.aspx "punch" <punch@discussions.microsoft.com> wro...

How to create pie chart with %
I have got a problem that I don't if excel could help me to calculate the % within a column and draw a pie chart. My case is I have a column containing a series of numbers. e.g. 1,4,8,1,3,9,11,2,4,5,6,.........etc I want to draw a pie chart that showing 1-3 , 4-6, 7-9, >9 with the corresponding % inside that column. Can anyone tell me how can I make it ? Ray - You need to calculate the frequencies in your data. Let's assume your data is in A1:A12. In B1:B3 enter these numbers, the upper limits on the groupings: 3 6 9 You can enter ">9" into B4 witho...

Email address not created when a new user is created
All, This issue recently happened in my company. Upon creating a new user, the policy was set to create the smtp and X400 address automaticaly. Now when we create a user the smtp and x400 addresses are not created, and when attempting to setup the new user in outlook, the address cant be found. We are using exchange 2003 SP1 on Win2k3 servers. On Wed, 13 Jul 2005 06:49:07 -0700, "Bryan" <Bryan@discussions.microsoft.com> wrote: >All, >This issue recently happened in my company. Upon creating a new user, the >policy was set to create the smtp and X400 addres...

Outlook Word Editor Curser Default
While typing an email in Outlook 2003 using MS Word editor, the curser goes to another location if you hesitate while composing the email. This drives a person crazy because you can't take your eyes off the screen for a moment. There is an option setting to set the curser off the default setting meaning the curser goes the message box automatically. This fixed it a over year ago, but when I downloaded updates the setting regressed back and I forgot how to correct this problem. HELP!! ...

How do I turn on drag and drop in MS Word 2007?
It seems that drag and drop has stopped working..... I have no clue why. There are instructions on how to turn drag and drop on/off for MS Word 2003, but I can't find the directions on how to do this for Word 2007. I'd like to turn this back on. Can anyone help? Click on the the Office Button (top/left) and at the bottom of that window click on Word Options. In that window choose Advanced. Drag and Drop is the third choice down. (That said... it doesn't always work even when you have selected it. Sigh) The problem could have to do with the Symbols dialog box. When you...

Macro to insert Hard Space (character 160)?
Hello, Is there a very simple macro out there that would let me insert character 160 (the hard space) into the current cell? I am looking for something like this because I want to be able to apply "accountant single" and "accountant double" underlining to a blank cell, and Excel seems to demand that some text be IN the cell before it will underline it. The hard space works perfectly, but it would be nice to be able to automate it. Many thanks for any advice, Edward Mendelson Sub HardSpace() ActiveCell.Value = ActiveCell.Value & Chr(160) End Sub Jerry Edward...

when form created
I have a form which was created by someone else (not a form template) which is like a questionnaire with empty boxes to be completed. When the boxes are typed in all the margins move to accommodate the words being typed. Is there a way to fix/lock the original form and then just fill in the blank boxes? I suspect this is set up as a table with auto resizing enabled. Displaying table gridlines (Table | Show Gridlines) will help you see what you're dealing with. Then select the table, go to the Table tab of Table Properties, click Options, and clear the check box for "A...

Exchange 2010 MRM, no log files being created
I'm hoping someone can help me with this issue....it has been driving me crazy for days. I have enabled MRM logging on our exchange server, and I can see that some of the policies are working when I run start-managedfolderassistant. We have a retention policy tag on the deleteditems folder, and this does work. The problem is I am not getting any files in the MRM log directory. C:\Program Files\Microsoft\Exchange Server\V14\Logging\Managed Folder Assistant Events 9021 and 9022 are logged in the Application log, but where are the files? Below is the output of my mai...

Creating a Brochure
How do you create a 3-column brochure from scratch for Publisher 2002? I can only find the directions for the 2003 version. Quick help would be appreciated, project is due Monday. Create a three-panel or four-panel folded publication http://office.microsoft.com/en-us/assistance/HP011646681033.aspx Scroll down to the section that says "Build a three-panel or four-panel publications from scratch." -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Derek" <Derek@discussions.microsoft.com> wrote in message news...

Enabling Macro But Hiding Sheets
I have created a simple macro that basically when a button is clicked i takes you to a certain page in the workbook. Is it possible to hide this page for different users. But when a use with the correct password comes he can click the button and he will b taken to the hidden page. Is it posible to do something like this along those line -- Message posted from http://www.ExcelForum.com It's possible, and if you search the archives: http://google.com/advanced_group_search?q=group:*excel* you'll find many ways to do this. You should know, however, that none of the methods will ...

How to create Access macro shortcut
I'm still using Access 97 and saw something the other day that I would like to use that was in Access 2000. In an Access 2000 database, there was a .mam file in a directory that launched the Access 2000 program and ran a macro. How do you set this up? Can it be done in Access 97? If so, how? Hi. > How do you set this up? Select the macro in the Database Window and right click with your mouse, then select "Create Shortcut..." in the pop-up menu. Follow the prompts for where to place the shortcut and what to name it. The default is: <PathToDeskTopDir>\Shortcut ...

Users mailboxes not created when user created
I have a problem that recently just started happening on my exchange 2003 server. When i create a new user account and create the mailbox for exchange, once im done, the mailbox isnt created, adn if you go into the properties of the user account adn go to the exchange email address tab, there isnt an smtp or an x.400 address listed. I am having to manually create and add these, adn then go delete the exchange mailbox and recreate it. This is really annoying and would love to know if anyone has any ideas of how to fix it. Thanks Jason In news:9F836A43-98BF-435A-AA43-AFF10124BE3F@micro...

Blue Toolbars in Publisher 2007
Anyway to change the color of the toolbars in Publisher 2007?...my eyes have a problem with blue. thanks...! -- glamart wrote: > Anyway to change the color of the toolbars in Publisher 2007?...my > eyes have a problem with blue. > thanks...! ================================== Changing your...Display Properties / Appearance... will also change the colors in your program UI. If you right click your desktop and choose... Properties / Appearance tab / Advanced button... open the 'Item' drop window and choose... 'Active Title Bar'....choose the colors you like for the...