S
simon.q.rice
Excel 2003
I am trying to write an error trap for a routine that saves a data
workbook to a USB drive, which is configured on drive E. The error
trap I'm after in this instance is when the user fails to put a USB
dive into the port. My code so far:
***************************************************************************************************************
option explicit
Sub LocalCopy()
Dim sFolder As Variant
'BC is a declared public variable
'Save data to USB drive
sFolder = "E:\Bradford\" & Format(Date, "dd-mm-yy")
MsgBox "Please insert your pen drive into the PC USB port",
vbInformation, "Saving local copy"
On Error GoTo ErrChk
MkDir sFolder
'Trap here if no USB drive inserted into PC
ActiveWorkbook.SaveCopyAs sFolder & "\" & BC & ".xls"
Application.DisplayStatusBar = True
Application.StatusBar = "Saving local copy and closing workbook ..."
ActiveWorkbook.Close (False)
Application.DisplayStatusBar = False
Exit Sub
ErrChk:
MsgBox "Please insert your pen drive into the PC USB port",
vbInformation, "Saving local copy"
ActiveWorkbook.SaveCopyAs sFolder & "\" & BC & ".xls"
Application.DisplayStatusBar = True
Application.StatusBar = "Saving local copy and closing workbook ..."
ActiveWorkbook.Close (False)
Application.DisplayStatusBar = False
End Sub
***************************************************************************************************************
Unfortunately even when there is no USB drive present, the code doesn't
error. Can somebody advise me on how I might check for the presence of
a USB drive. I have tried a number of options from searches of this
usergroup but so far to no avail.
Thank you
Simon
I am trying to write an error trap for a routine that saves a data
workbook to a USB drive, which is configured on drive E. The error
trap I'm after in this instance is when the user fails to put a USB
dive into the port. My code so far:
***************************************************************************************************************
option explicit
Sub LocalCopy()
Dim sFolder As Variant
'BC is a declared public variable
'Save data to USB drive
sFolder = "E:\Bradford\" & Format(Date, "dd-mm-yy")
MsgBox "Please insert your pen drive into the PC USB port",
vbInformation, "Saving local copy"
On Error GoTo ErrChk
MkDir sFolder
'Trap here if no USB drive inserted into PC
ActiveWorkbook.SaveCopyAs sFolder & "\" & BC & ".xls"
Application.DisplayStatusBar = True
Application.StatusBar = "Saving local copy and closing workbook ..."
ActiveWorkbook.Close (False)
Application.DisplayStatusBar = False
Exit Sub
ErrChk:
MsgBox "Please insert your pen drive into the PC USB port",
vbInformation, "Saving local copy"
ActiveWorkbook.SaveCopyAs sFolder & "\" & BC & ".xls"
Application.DisplayStatusBar = True
Application.StatusBar = "Saving local copy and closing workbook ..."
ActiveWorkbook.Close (False)
Application.DisplayStatusBar = False
End Sub
***************************************************************************************************************
Unfortunately even when there is no USB drive present, the code doesn't
error. Can somebody advise me on how I might check for the presence of
a USB drive. I have tried a number of options from searches of this
usergroup but so far to no avail.
Thank you
Simon