m_in_spain
Board Regular
- Joined
- Sep 28, 2018
- Messages
- 64
- Office Version
- 365
- Platform
- Windows
Hi
I have written the following code which takes a file and stores it in my temp directory ready for a later stage. Seems to work well, however, the file can be anything, doc, picture, ppt, etc etc.
this is my code:
Is there a way I can check if the file saved is a PDF file, if it is not (i.e. any other file type) i need to print it to the same folder as a PDF with the same file name, and keep the native file there too?
Thanks, as ever, if there is any help out there!
I have written the following code which takes a file and stores it in my temp directory ready for a later stage. Seems to work well, however, the file can be anything, doc, picture, ppt, etc etc.
this is my code:
VBA Code:
'COPIES THE REQUESTED ATTACHMENT FILE AND RENAMES IT PROJECT SPECIFIC TO C:\TEMP\makePO FOLDER
Sub CopyAttachment()
Dim FSO
Dim sFile As String
Dim sSFolder As String
Dim sDFolder As String
Dim newfilename As String
'Ends sub if no attachment specified
If Range("FilePath") = "" Then End
'This is the file to be copied
sFile = Range("attchFILE")
'This is the source folder path
sSFolder = Range("attchPATH")
'This is the Save destination directory
'Checks to see if save directory is there
If Dir("c:\temp\makePO", vbDirectory) = "" Then
'directory doesn't exist
MkDir path:="C:\temp\makePO"
Else
'directory does exist
End If
'This is the destination folder path
sDFolder = "C:\temp\makePO\"
'Rename the copied file to Project Specific
newfilename = Range("AttchNewName")
'Create Object
Set FSO = CreateObject("Scripting.FileSystemObject")
'If file already exists then it is silently overwritten
Application.DisplayAlerts = False
FSO.CopyFile (sSFolder & sFile), sDFolder & newfilename, True
Application.DisplayAlerts = True
End Sub
Is there a way I can check if the file saved is a PDF file, if it is not (i.e. any other file type) i need to print it to the same folder as a PDF with the same file name, and keep the native file there too?
Thanks, as ever, if there is any help out there!