M
Matt S
Hi,
I've written a macro and have gotten to the point where I'd like the macro
to save the file. I'm trying to make the macro as easy to use as possible.
To that end, I'd like the macro to save the generated file to a USB stick,
which has a drive letter that is variable. It is either E: or F:, depending
on which stick is used. The user can either save to the desktop or to the
USB key. What I'd like to happen is if the drive is not E then try F. If it
is neither, then a USB stick is not inserted and a message should pop up to
say restart the macro after inserting the stick and the macro should end.
Currently, only an error pops up to debug if no stick is inserted (which I do
not want them to do).
This is what I have so far:
' Method to save file either to USB stick or to Desktop
Dim fPath As String
fPath = "C:\Documents and Settings\" & Environ("username") & "\Desktop\"
file = ActiveWorkbook.Name
Windows("HELO Macros.xls").Activate
If Range("D3") = "To Stick" Then
Windows(file).Activate
ActiveWorkbook.SaveAs Filename:="E:\Runlogs\" & Name & "-" &
ilngFileNumber, FileFormat:=xlWorkbookNormal
ElseIf Range("D3") = "To Desktop" Then
Windows(file).Activate
ActiveWorkbook.SaveAs Filename:=fPath & Name & "-" & ilngFileNumber,
FileFormat:=xlWorkbookNormal
End If
Thank you!
Matt
I've written a macro and have gotten to the point where I'd like the macro
to save the file. I'm trying to make the macro as easy to use as possible.
To that end, I'd like the macro to save the generated file to a USB stick,
which has a drive letter that is variable. It is either E: or F:, depending
on which stick is used. The user can either save to the desktop or to the
USB key. What I'd like to happen is if the drive is not E then try F. If it
is neither, then a USB stick is not inserted and a message should pop up to
say restart the macro after inserting the stick and the macro should end.
Currently, only an error pops up to debug if no stick is inserted (which I do
not want them to do).
This is what I have so far:
' Method to save file either to USB stick or to Desktop
Dim fPath As String
fPath = "C:\Documents and Settings\" & Environ("username") & "\Desktop\"
file = ActiveWorkbook.Name
Windows("HELO Macros.xls").Activate
If Range("D3") = "To Stick" Then
Windows(file).Activate
ActiveWorkbook.SaveAs Filename:="E:\Runlogs\" & Name & "-" &
ilngFileNumber, FileFormat:=xlWorkbookNormal
ElseIf Range("D3") = "To Desktop" Then
Windows(file).Activate
ActiveWorkbook.SaveAs Filename:=fPath & Name & "-" & ilngFileNumber,
FileFormat:=xlWorkbookNormal
End If
Thank you!
Matt