Saving or Linking a workbook on two drives

M

Mark

I have a workbook saved on my local hard drive, but i want to save or link it
to a workbook on the network drive. Of course the files are the same format,
basically so other can access without having to 'save' twice?
 
L

Lionel H

I do something like that with my Personal.xls workbook. Not to share with
others, just for peace of mind in case my laptop gets nicked. It means I
don't have to remember to save it once never mind twice. It also means
writing code, and since you are in the General Questions section, I don't
know how familiar you are with that, but here goes. I've modified my code
slightly but it should work for you if you change the constants to point at
drive paths relevant to you.

In the code page for the 'ThisWorkbook' object put:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Archive_PWB
End Sub

The rest can go in any module in the same workbook, but for simplicity you
could put it in the same place (but if you do, the constants must go to the
top of the sheet):

Const Localpath As String = "C:\mySharedFiles\"
Const Networkpath As String = "\\myNetworkDrive\myFolder\"

Public Sub Archive_PWB()
If Not ActiveWorkbook.Saved Then
'Save it locally (if new) or overwrite existing (if not) before ...
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Localpath & ActiveWorkbook.Name
Application.DisplayAlerts = True
'... doing the archive
Copy_to_Network_Drive
End If
Exit Sub
End Sub
Private Sub Copy_to_Network_Drive()
Dim Answer As String
Dim fsObject As Object
On Error GoTo eCode
Set fsObject = CreateObject("Scripting.FileSystemObject")
fsObject.copyfile _
Localpath & ActiveWorkbook.Name, _
Networkpath & ActiveWorkbook.Name, _
True 'overwrite
Set fsObject = Nothing
Exit Sub
eCode:
If Err.Number = 76 Then
'Network Drive unavailable.
Answer = InputBox("Network drive unavailable continue without
saving?" & vbCrLf & _
"If No, make it available before continuing.", _
"Copy_to_Network_Drive", "Y")
If UCase(Answer) = "Y" Then
Resume Next
Else
Resume
End If
Else
MsgBox "Unexpected error: " & Err.Number & " - " & Err.Description,
, _
"Copy_to_Network_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