Link to Excel File on Outlook Form, like hyperlink click and it opens

F

freeman642

I need to have a link on an Outlook VBA form that links and opens an
excel file, does anyone know of a way to do this? Have seen links to
internet explorer but not opening a file on a shared network drive.
Thanks John
 
G

Guest

The code to open a file needs the following Win32 API declaration in the
General Declarations section of a new Module (you can't put it in the code
behind the UserForm):

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String _
, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal
nShowCmd As Long) As Long

Then you can launch the file like this:

Dim varRet As Variant
varRet = Shell("""C:\Program Files\Microsoft Office\Office12\EXCEL.EXE""
""C:\Temp\myworkbook.xls""", vbNormalFocus)

Change 12 in the file path to 11 if you are using Office 2003.

The trickiest part is making the user think he's clicking on a hyperlink.
None of the built-in controls are satisfactory for replicating a true "URL
clicking experience". For example, you'd have to manually make the text blue
and underlined and write additional code to change the cursor to a
hand-with-finger during a MouseOver event for the control.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top