G
Guest
Hello,
I am trying to open a file from word and excel from my database.
I am using this code, it works fine for pdf and image files.
doc and xls files only work as long as there are no spacing in the name.
When there are spaces in the name I get errors in both word and excel
Public Sub Open_File(Filename As String)
On Error GoTo Err_Click
Dim I As Integer, E As String, Prog As String
'Extensie zoeken
I = InStr(1, Filename, ".")
If I = 0 Then Exit Sub
E = Mid(Filename, I + 1, Len(Filename) - I)
'Juiste programma selecteren
Select Case E
Case "jpg", "jpeg", "bmp", "tif", "tiff"
Prog = "C:\WINDOWS\SYSTEM32\MSPAINT.EXE"
Case "doc"
Prog = "C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE"
Case "xls"
Prog = "C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE"
Case "pdf"
Prog = "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe"
Case Else
Exit Sub
End Select
'Applicatie openen
Prog = Prog & " " & Filename
Call Shell(Prog, 1)
Exit_Click:
Exit Sub
Err_Click:
MsgBox Err.Description
Resume Exit_Click
End Sub
I am trying to open a file from word and excel from my database.
I am using this code, it works fine for pdf and image files.
doc and xls files only work as long as there are no spacing in the name.
When there are spaces in the name I get errors in both word and excel
Public Sub Open_File(Filename As String)
On Error GoTo Err_Click
Dim I As Integer, E As String, Prog As String
'Extensie zoeken
I = InStr(1, Filename, ".")
If I = 0 Then Exit Sub
E = Mid(Filename, I + 1, Len(Filename) - I)
'Juiste programma selecteren
Select Case E
Case "jpg", "jpeg", "bmp", "tif", "tiff"
Prog = "C:\WINDOWS\SYSTEM32\MSPAINT.EXE"
Case "doc"
Prog = "C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE"
Case "xls"
Prog = "C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE"
Case "pdf"
Prog = "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe"
Case Else
Exit Sub
End Select
'Applicatie openen
Prog = Prog & " " & Filename
Call Shell(Prog, 1)
Exit_Click:
Exit Sub
Err_Click:
MsgBox Err.Description
Resume Exit_Click
End Sub