Hello all,
The following code is supposed to detect the letter of the flash drive if one is plugged in, then save the active workbook in both .xlsm and .pdf formats:
Sub usbSave()
On Error Resume Next
Dim i As Integer
Dim PDFfileName As String
Set fs = CreateObject("Scripting.FileSystemObject")
For i = 67 To 90
Set drspec = fs.GetDrive(Chr(i))
If drspec.drivetype = 1 Then
'PDFfileName = Range("H5").Value
MsgBox "File saved to USB Drive (" & Chr(i) & ":\)"
spath = Chr(i) & ":\"
sFilename = Range("H5").Value & ".xlsm"
PDFfileName = spath & Range("H5").Value & ".pdf"
ActiveWorkbook.SaveCopyAs spath & sFilename
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=PDFfileName, openafterpublish:=False
i = 90
End If
Next i
End Sub
The .xlsm feature works, the .pdf part does not. Any ideas?
Best,
Willardio
Bookmarks