Error Trapping saving file to network drive

G

Gazza

I have a simple save routine which saves the file to my own c drive and then
a copy to a network drive. How can I run the sproceedure and trap the error
if the pc is not connected to the network.

Also would it be possible to trap another error - say if the file had been
opened by someone using the network drive copy, to ignore the second part of
the routine too and perhaps send a message back to the user that it has been
saved to the local drive but not the network.

Sub SaveOptions()
'
' SaveOptions Macro
' Macro recorded 25/09/2006 by Gary Mallin

'Save to own hard-drive

ChDir "C:\Documents and Settings\malling\My Documents\Gary's Documents"
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\malling\My Documents\Gary's
Documents\TOIL 2006-2007 Gary.xls" _
, FileFormat:=xlNormal, Password:="gazzaflexi", WriteResPassword:=
_
"", ReadOnlyRecommended:=False, CreateBackup:=False


'Save to Network Drive

ChDir "Z:\man ac\Preston06-07\TOIL"
ActiveWorkbook.SaveAs Filename:= _
"Z:\man ac\Preston06-07\TOIL\TOIL 2006-2007 Gary.xls",
FileFormat:=xlNormal, _
Password:="gazzaflexi", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

End Sub

As always help from this forum greatly appreciated

Gaz
 
T

Tom Ogilvy

Sub SaveOptions()
'
' SaveOptions Macro
' Macro recorded 25/09/2006 by Gary Mallin

'Save to own hard-drive

ChDir "C:\Documents and Settings\malling\My Documents\Gary's Documents"
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\malling\My Documents\Gary's
Documents\TOIL 2006-2007 Gary.xls" _
, FileFormat:=xlNormal, Password:="gazzaflexi", WriteResPassword:=
_
"", ReadOnlyRecommended:=False, CreateBackup:=False


'Save to Network Drive

on error Resume Next
ChDir "Z:\man ac\Preston06-07\TOIL"
ActiveWorkbook.SaveAs Filename:= _
"Z:\man ac\Preston06-07\TOIL\TOIL 2006-2007 Gary.xls",
FileFormat:=xlNormal, _
Password:="gazzaflexi", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
On Error goto 0
if Left(Activeworkbook.Path,1) <> "Z" then
msgbox "Only saved to local drive"
end if

End Sub
 
G

Gazza

Thanks Tom

kind regards

Gary


Tom Ogilvy said:
Sub SaveOptions()
'
' SaveOptions Macro
' Macro recorded 25/09/2006 by Gary Mallin

'Save to own hard-drive

ChDir "C:\Documents and Settings\malling\My Documents\Gary's Documents"
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\malling\My Documents\Gary's
Documents\TOIL 2006-2007 Gary.xls" _
, FileFormat:=xlNormal, Password:="gazzaflexi", WriteResPassword:=
_
"", ReadOnlyRecommended:=False, CreateBackup:=False


'Save to Network Drive

on error Resume Next
ChDir "Z:\man ac\Preston06-07\TOIL"
ActiveWorkbook.SaveAs Filename:= _
"Z:\man ac\Preston06-07\TOIL\TOIL 2006-2007 Gary.xls",
FileFormat:=xlNormal, _
Password:="gazzaflexi", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
On Error goto 0
if Left(Activeworkbook.Path,1) <> "Z" then
msgbox "Only saved to local drive"
end if

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top