Hello,
i have a code that opens a word document from a path written in a certain cell.
currently it opens only word documents
is there a way to adujst it so it will open pdf files alos?
here is the code:
'Reference : Microsoft Word 16.0 Object Library
'----------------------------------------------
Sub infotour()
Dim strFName As String
Dim objWord, objDoc
strFName = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\Excel\" & Sheet11.Range("P21").Value
If FileExists(strFName) And strFName <> "" Then
If Not IsFileOpen(strFName) Then
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(strFName)
objWord.Visible = True
Else
MsgBox "The File Is Already Open", vbExclamation
End If
Else
MsgBox "The File Does Not Exist!", vbExclamation
End If
End Sub
Function FileExists(strfullname As String) As Boolean
FileExists = Dir(strfullname) <> ""
End Function
Function IsFileOpen(fName As String) As Boolean
Dim i As Integer, errNum As Integer
If Dir(fName, 0) = "" Then
IsFileOpen = False: Exit Function
End If
On Error Resume Next
i = FreeFile
Open fName For Input Lock Read As #i
Close i
errNum = Err
On Error GoTo 0
IsFileOpen = (errNum <> 0)
End Function
Thanks in Advance,
Avi
Bookmarks