I have a EXCEL VBA 'export to PDF' app that uses DIR to verify the EXP_PDF.dll file exists. The function returns the file, but the file is actually located in a directory different than what (I think) the DIR path points to. I built the following simple sub to test:
Sub RetrieveFile()
Dim Shex As Object
Set Shex = CreateObject("Shell.Application")
file = Dir(Environ("commonprogramfiles") & "\Microsoft Shared\OFFICE" & Format(Val(Application.Version), "00") & "\EXp_PDF.DLL")
Path = Environ("commonprogramfiles") & "\Microsoft Shared\OFFICE" & Format(Val(Application.Version), "00")
targetFile = Path & "\EXp_PDF.DLL"
If Len(file) > 0 Then
MsgBox (targetFile & " Exists")
Debug.Print targetFile
FileCopy targetFile, "C:\Temp\exp_pdf.dll"
tgtfile = targetFile
Shex.Open (tgtfile)
Else
MsgBox ("File Doesn't Exist")
End If
End Sub
- The DIR function returns the file name with length greater than 0
- msgbox displays a path. (but there are no files in the directory. Searching windows finds the file in a different directory.)
- the "file copy" code is copies the file to the temp directory
- The "file open" code launches but reports that the file cannot be found
Background: We have engineering logbook built in excel that uses a VBA app to export to pdf and email. It looks like the code originated on MSDN and was probably built for office 2007. Recently WIN 10 Office 16 computers did a windows update and the code now fails. I restored function by commenting out the search for the EXP_PDF.dll but I would like to know why the DIR function seems to be finding the dll in other location and yes hidden and windows files are set to shown. Thanks.