Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Lee Lee is offline
external usenet poster
 
Posts: 33
Default Word VBA Code to Excel Code

I have some code that opens a FileDialog box and the user
can click on a document which will in turn, insert a
hyperlink into a document. This code runs in Word and I
have been asked to change this so it runs in Excel as
well.. Problem is, I've never written for Excel before and
I'm only a learner of VBA in Word. (We are using 2002).

The code is used to insert a hyperlink from a certain
folder. The Word VBA I have 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://
\\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

I tried to change the line "ActiveDocument.Hyperlinks.Add
Anchor:=Selection.Range, Address:=.SelectedItems(1),
TextToDisplay:=displaytext" for Excel but don't know how
or what I need to do. The rest of the code runs, e.g. the
FileDialog box opens in the right folder etc...

Help please !! Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Word VBA Code to Excel Code

Lee,
Recorder a macro whilst inserting your hyperlink in Excel. That code plus
the openfile should get you sorted.

NickHK

"Lee" wrote in message
...
I have some code that opens a FileDialog box and the user
can click on a document which will in turn, insert a
hyperlink into a document. This code runs in Word and I
have been asked to change this so it runs in Excel as
well.. Problem is, I've never written for Excel before and
I'm only a learner of VBA in Word. (We are using 2002).

The code is used to insert a hyperlink from a certain
folder. The Word VBA I have 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://
\\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

I tried to change the line "ActiveDocument.Hyperlinks.Add
Anchor:=Selection.Range, Address:=.SelectedItems(1),
TextToDisplay:=displaytext" for Excel but don't know how
or what I need to do. The rest of the code runs, e.g. the
FileDialog box opens in the right folder etc...

Help please !! Thanks



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I change text to bar code in word or excel? Rik Excel Discussion (Misc queries) 2 February 20th 07 09:08 PM
Word equivalent of Excel code Mohan[_2_] Excel Programming 1 March 3rd 04 04:47 PM
How to open a Word or HTML document using VBA code in Excel TBA[_2_] Excel Programming 1 January 21st 04 03:19 AM
Excel code to Wait until Word finishes printing before closing Mike Molyneaux[_2_] Excel Programming 2 October 24th 03 02:45 AM


All times are GMT +1. The time now is 12:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"