Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
EPPack EPPack is offline
external usenet poster
 
Posts: 2
Default 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
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default Create hyperlink via macro? Word 2007

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



  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default Create hyperlink via macro? Word 2007

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



  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Pesach Shelnitz[_2_] Pesach Shelnitz[_2_] is offline
external usenet poster
 
Posts: 277
Default Create hyperlink via macro? Word 2007

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

  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Pesach Shelnitz[_2_] Pesach Shelnitz[_2_] is offline
external usenet poster
 
Posts: 277
Default Create hyperlink via macro? Word 2007

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

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hyperlink to Run a Macro WordWorker Microsoft Word Help 5 May 7th 23 08:50 PM
How to create an email from mail merge including a hyperlink, so that the value of a merged field is included as part of the hyperlink URL, not just part of its text. [email protected] Mailmerge 4 August 22nd 07 06:18 PM
How to create an email from mail merge including a hyperlink, so that the value of a merged field is included as part of the hyperlink URL, not just part of its text. [email protected] Mailmerge 0 August 17th 07 03:52 PM
Can I create a hyperlink in Word to a PDF file EJB Microsoft Word Help 4 September 5th 06 08:34 PM
Word: I create a hyperlink to a pdf. I ctrl-click on hyperlink, . Bruce Microsoft Word Help 0 February 18th 05 03:57 AM


All times are GMT +1. The time now is 01:52 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"