I have create a custom toolbar which leave within a
Startup Template. When clicked, this toolbar runs the
following code which inserts a hyperlink.

Sub Hyperlink()

Dim fd As FileDialog, displaytext As String
'Create a FileDialog object as a File Picker dialog
box.
Set fd = Application.FileDialog
(msoFileDialogFilePicker)
'Use a With...End With block to reference the
FileDialog object.
With fd
'Set the initial path to the Agenda Attachments
folder.
.InitialFileName
= "\\alchemy\data\processes\documents\agenda attachments\"
.Title = "Select the File to which you want to
create the link"
'Use the Show method to display the File Picker
dialog box and return the user's action.
'If the user presses the action button...
If .Show = -1 Then
displaytext = .SelectedItems(1)
While InStr(displaytext, "\") > 0
displaytext = Mid(displaytext, InStr
(displaytext, "\") + 1)
Wend
displaytext = Left(displaytext, Len
(displaytext) - 4)
ActiveDocument.Hyperlinks.Add
Anchor:=Selection.Range, Address:=.SelectedItems(1),
TextToDisplay:=displaytext
' 'If the user presses Cancel...
Else
End If
End With

'Set the object variable to Nothing.
Set fd = Nothing

End Sub

The problem I am now having is that when the document (new
doc based on template) is saved, it changes the hyperlink
from \\alchemy\data\processes\documents\agenda
attachments\(filename)
to ..\data\processes\documents\agenda
attachments\(filename) so it loses it's link.

Any ideas why?

Custom Toolbar within Template by DA

DA
Mon Aug 09 01:29:59 CDT 2004

Hi Lee

Try something like the following instead. This will
return the absolute path. Note that you have to include
the "Microsoft Scripting Runtime" reference for it to
work (Under Tools>References).

---------------
Sub Hyperlink()
Dim myFilObj As New Scripting.FileSystemObject
Dim strLinkURL As String
Dim strLinkText As String

With Dialogs(wdDialogFileOpen)
.Name = "\\alchemy\data\processes\documents\agenda
attachments\*.*"
If .Display = -1 Then
strLinkURL = myFilObj.GetAbsolutePathName(CurDir) _
& .Name
strLinkText = Left(.Name, Len(.Name) - 4)
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
Address:=strLinkURL, TextToDisplay:=strLinkText
End If
End With

End Sub
-----------------
Hope that helps,
Dennis


>-----Original Message-----
>I have create a custom toolbar which leave within a
>Startup Template. When clicked, this toolbar runs the
>following code which inserts a hyperlink.
>
>Sub Hyperlink()
>
>Dim fd As FileDialog, displaytext As String
> 'Create a FileDialog object as a File Picker dialog
>box.
> Set fd = Application.FileDialog
>(msoFileDialogFilePicker)
> 'Use a With...End With block to reference the
>FileDialog object.
> With fd
> 'Set the initial path to the Agenda Attachments
>folder.
> .InitialFileName
>= "\\alchemy\data\processes\documents\agenda
attachments\"
> .Title = "Select the File to which you want to
>create the link"
> 'Use the Show method to display the File Picker
>dialog box and return the user's action.
> 'If the user presses the action button...
> If .Show = -1 Then
> displaytext = .SelectedItems(1)
> While InStr(displaytext, "\") > 0
> displaytext = Mid(displaytext, InStr
>(displaytext, "\") + 1)
> Wend
> displaytext = Left(displaytext, Len
>(displaytext) - 4)
> ActiveDocument.Hyperlinks.Add
>Anchor:=Selection.Range, Address:=.SelectedItems(1),
>TextToDisplay:=displaytext
>' 'If the user presses Cancel...
> Else
> End If
> End With
>
> 'Set the object variable to Nothing.
> Set fd = Nothing
>
>End Sub
>
>The problem I am now having is that when the document
(new
>doc based on template) is saved, it changes the
hyperlink
>from \\alchemy\data\processes\documents\agenda
>attachments\(filename)
>to ..\data\processes\documents\agenda
>attachments\(filename) so it loses it's link.
>
>Any ideas why?
>.
>

Custom Toolbar within Template by Lee

Lee
Mon Aug 09 19:59:56 CDT 2004

Hi Dennis

I tried the following but it still changed the link path
from \\alchemy\data\etc to ..\data\
???????????????

Thanks anyway :o)

>-----Original Message-----
>Hi Lee
>
>Try something like the following instead. This will
>return the absolute path. Note that you have to include
>the "Microsoft Scripting Runtime" reference for it to
>work (Under Tools>References).
>
>---------------
>Sub Hyperlink()
>Dim myFilObj As New Scripting.FileSystemObject
>Dim strLinkURL As String
>Dim strLinkText As String
>
>With Dialogs(wdDialogFileOpen)
> .Name = "\\alchemy\data\processes\documents\agenda
>attachments\*.*"
> If .Display = -1 Then
> strLinkURL = myFilObj.GetAbsolutePathName(CurDir) _
> & .Name
> strLinkText = Left(.Name, Len(.Name) - 4)
> ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
> Address:=strLinkURL, TextToDisplay:=strLinkText
> End If
>End With
>
>End Sub
>-----------------
>Hope that helps,
>Dennis
>
>
>>-----Original Message-----
>>I have create a custom toolbar which leave within a
>>Startup Template. When clicked, this toolbar runs the
>>following code which inserts a hyperlink.
>>
>>Sub Hyperlink()
>>
>>Dim fd As FileDialog, displaytext As String
>> 'Create a FileDialog object as a File Picker dialog
>>box.
>> Set fd = Application.FileDialog
>>(msoFileDialogFilePicker)
>> 'Use a With...End With block to reference the
>>FileDialog object.
>> With fd
>> 'Set the initial path to the Agenda Attachments
>>folder.
>> .InitialFileName
>>= "\\alchemy\data\processes\documents\agenda
>attachments\"
>> .Title = "Select the File to which you want to
>>create the link"
>> 'Use the Show method to display the File Picker
>>dialog box and return the user's action.
>> 'If the user presses the action button...
>> If .Show = -1 Then
>> displaytext = .SelectedItems(1)
>> While InStr(displaytext, "\") > 0
>> displaytext = Mid(displaytext, InStr
>>(displaytext, "\") + 1)
>> Wend
>> displaytext = Left(displaytext, Len
>>(displaytext) - 4)
>> ActiveDocument.Hyperlinks.Add
>>Anchor:=Selection.Range, Address:=.SelectedItems(1),
>>TextToDisplay:=displaytext
>>' 'If the user presses Cancel...
>> Else
>> End If
>> End With
>>
>> 'Set the object variable to Nothing.
>> Set fd = Nothing
>>
>>End Sub
>>
>>The problem I am now having is that when the document
>(new
>>doc based on template) is saved, it changes the
>hyperlink
>>from \\alchemy\data\processes\documents\agenda
>>attachments\(filename)
>>to ..\data\processes\documents\agenda
>>attachments\(filename) so it loses it's link.
>>
>>Any ideas why?
>>.
>>
>.
>

Custom Toolbar within Template by Lee

Lee
Thu Aug 12 19:39:20 CDT 2004

Hi All

Thought I would let you know that I have fixed this now.
Fixed coding that works is:

>>>Sub Hyperlink()
>>>
>>>Dim fd As FileDialog, displaytext As String
>>> 'Create a FileDialog object as a File Picker dialog
>>>box.
>>> Set fd = Application.FileDialog
>>>(msoFileDialogFilePicker)
>>> 'Use a With...End With block to reference the
>>>FileDialog object.
>>> With fd
>>> 'Set the initial path to the Agenda Attachments
>>>folder.
>>> .InitialFileName
>>>= "file://M:\data\processes\documents\agenda
>>attachments\"
>>> .Title = "Select the File to which you want to
>>>create the link"
>>> 'Use the Show method to display the File Picker
>>>dialog box and return the user's action.
>>> 'If the user presses the action button...
>>> If .Show = -1 Then
>>> displaytext = .SelectedItems(1)
>>> While InStr(displaytext, "\") > 0
>>> displaytext = Mid(displaytext, InStr
>>>(displaytext, "\") + 1)
>>> Wend
>>> displaytext = Left(displaytext, Len
>>>(displaytext) - 4)
>>> ActiveDocument.Hyperlinks.Add
>>>Anchor:=Selection.Range, Address:=.SelectedItems(1),
>>>TextToDisplay:=displaytext
>>>' 'If the user presses Cancel...
>>> Else
>>> End If
>>> End With
>>>
>>> 'Set the object variable to Nothing.
>>> Set fd = Nothing
>>>
>>>End Sub

Thanks to all who helped with this coding.

>-----Original Message-----
>Hi Dennis
>
>I tried the following but it still changed the link path
>from \\alchemy\data\etc to ..\data\
>???????????????
>
>Thanks anyway :o)
>
>>-----Original Message-----
>>Hi Lee
>>
>>Try something like the following instead. This will
>>return the absolute path. Note that you have to include
>>the "Microsoft Scripting Runtime" reference for it to
>>work (Under Tools>References).
>>
>>---------------
>>Sub Hyperlink()
>>Dim myFilObj As New Scripting.FileSystemObject
>>Dim strLinkURL As String
>>Dim strLinkText As String
>>
>>With Dialogs(wdDialogFileOpen)
>> .Name = "\\alchemy\data\processes\documents\agenda
>>attachments\*.*"
>> If .Display = -1 Then
>> strLinkURL = myFilObj.GetAbsolutePathName(CurDir) _
>> & .Name
>> strLinkText = Left(.Name, Len(.Name) - 4)
>> ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range,
_
>> Address:=strLinkURL, TextToDisplay:=strLinkText
>> End If
>>End With
>>
>>End Sub
>>-----------------
>>Hope that helps,
>>Dennis
>>
>>
>>>-----Original Message-----
>>>I have create a custom toolbar which leave within a
>>>Startup Template. When clicked, this toolbar runs the
>>>following code which inserts a hyperlink.
>>>
>>>Sub Hyperlink()
>>>
>>>Dim fd As FileDialog, displaytext As String
>>> 'Create a FileDialog object as a File Picker dialog
>>>box.
>>> Set fd = Application.FileDialog
>>>(msoFileDialogFilePicker)
>>> 'Use a With...End With block to reference the
>>>FileDialog object.
>>> With fd
>>> 'Set the initial path to the Agenda Attachments
>>>folder.
>>> .InitialFileName
>>>= "\\alchemy\data\processes\documents\agenda
>>attachments\"
>>> .Title = "Select the File to which you want to
>>>create the link"
>>> 'Use the Show method to display the File Picker
>>>dialog box and return the user's action.
>>> 'If the user presses the action button...
>>> If .Show = -1 Then
>>> displaytext = .SelectedItems(1)
>>> While InStr(displaytext, "\") > 0
>>> displaytext = Mid(displaytext, InStr
>>>(displaytext, "\") + 1)
>>> Wend
>>> displaytext = Left(displaytext, Len
>>>(displaytext) - 4)
>>> ActiveDocument.Hyperlinks.Add
>>>Anchor:=Selection.Range, Address:=.SelectedItems(1),
>>>TextToDisplay:=displaytext
>>>' 'If the user presses Cancel...
>>> Else
>>> End If
>>> End With
>>>
>>> 'Set the object variable to Nothing.
>>> Set fd = Nothing
>>>
>>>End Sub
>>>
>>>The problem I am now having is that when the document
>>(new
>>>doc based on template) is saved, it changes the
>>hyperlink
>>>from \\alchemy\data\processes\documents\agenda
>>>attachments\(filename)
>>>to ..\data\processes\documents\agenda
>>>attachments\(filename) so it loses it's link.
>>>
>>>Any ideas why?
>>>.
>>>
>>.
>>
>.
>