Hi,
I'm using the code below to open different kind of files. But it doesn't work with, for example, Excel files. I'd like to have one universal code for opening files.
What's wrong? I'm using Office 2000, Windows XP Professional, SP2.
Thanks in advance,
pbazsmir
I'm using the code below to open different kind of files. But it doesn't work with, for example, Excel files. I'd like to have one universal code for opening files.
Code:
Option Explicit
Private Const SW_SHOWNORMAL = 1
Private 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
Sub OpenFile()
Dim Hwnd As Long
Const FileName = "c:\temp\data.xls"
On Error GoTo Errorhandler
ShellExecute Hwnd, vbNullString, FileName, vbNullString, _
vbNullString, SW_SHOWNORMAL
Exit Sub
Errorhandler:
'MsgBox "Error: " & Err.Number
MsgBox "Error occured. I can't open the file"
Exit Sub
End Sub
What's wrong? I'm using Office 2000, Windows XP Professional, SP2.
Thanks in advance,
pbazsmir