Save in three locations

M

mikefnz

I've been using Grahm Mayor's excellent vba to save in two locations. Now I
need to save in three locations and need to tweak the original code.

My efforts need some refinement!

Any suggestions would be greatly appreciated.

Cheers

Mike

Sub backup2()
'
' backup2 Macro
'
'

Dim strFileA As String
Dim strFileB As String
Dim strFileC As String
Dim strFileD As String
ActiveDocument.Save
strFileA = ActiveDocument.Name

'Define backup path shown in blue below
strFileD = "F:\Temp word backups\Backup " & strFileA
strFileB = "D:\Temp word backups\Backup " & strFileA
strFileC = ActiveDocument.FullName

ActiveDocument.SaveAs FileName:=strFileD
ActiveDocument.SaveAs FileName:=strFileB
ActiveDocument.SaveAs FileName:=strFileC

End Sub
 
G

Graham Mayor

Are we to suppose that you want to backup the file to two locations?

"F:\Temp word backups\"
"D:\Temp word backups\"

That being the case, are D & F permanently available hard drives or some
other form of media?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

The problem with external media is that it may not always be available, so a
simple macro like the one shown will result in error when the drive is
missing.

Dim strFileA As String
Dim strFileB As String
Dim strFileC As String
Dim strFileD As String
Dim oDoc As Word.Document
Set oDoc = ActiveDocument
oDoc.Save
With oDoc
strFileA = .name
'Define backup path shown in blue below
strFileB = "D:\Temp word backups\Backup " & strFileA
strFileC = "F:\Temp word backups\Backup " & strFileA
strFileD = .FullName
.SaveAs FileName:=strFileB
.SaveAs FileName:=strFileC
.SaveAs FileName:=strFileD
End With
ActiveWindow.Caption = ActiveDocument.FullName

If you want to trap the possibility of that external drive being
unavailable, then the following macro will do that and provide an option to
save elsewhere. I have assumed that the D drive and folder thereon will
always be available.

Dim strFileA As String
Dim strFileB As String
Dim strFileC As String
Dim strFileD As String
Dim oDoc As Word.Document
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
Set oDoc = ActiveDocument
oDoc.Save
On Error GoTo Errorhandler
With oDoc
strFileA = .name
strFileB = "D:\Temp word backups\Backup " & strFileA
strFileC = "F:\Temp word backups\Backup " & strFileA
strFileD = .FullName
.SaveAs FileName:=strFileB
.SaveAs FileName:=strFileC
.SaveAs FileName:=strFileD
End With
ActiveWindow.Caption = ActiveDocument.FullName
Exit Sub
Errorhandler:
If Err.Number = 5152 Then
sQuery = MsgBox("Backup location not available. Choose another?",
vbYesNo, _
"Missing folder")
If sQuery = vbYes Then
'Get the folder for the revised backup location
With fDialog
.Title = "Select folder to save the copy and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , "Save to new location"
Exit Sub
End If
strPathA = fDialog.SelectedItems.Item(1)
If Right(strPathA, 1) <> "\" Then strPathA = strPathA & "\"
End With
oDoc.SaveAs strPathA & strFileA
End If
Else
MsgBox "Backup not saved!", vbCritical, "Error!"
End If
oDoc.SaveAs FileName:=strFileD
ActiveWindow.Caption = ActiveDocument.FullName


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

mikefnz

Hi Graham

Many thanks for taking the time to provide such a detailed response.

The simple macro works well. I love the addtional caption information.

The more involved macro throws up a syntax error at:

sQuery = MsgBox("Backup location not available. Choose another?",

What do you want for Christmas?

Cheers

Mike
 
D

Doug Robbins - Word MVP

All of the following should be on one line

sQuery = MsgBox("Backup location not available. Choose another?",
vbYesNo, _

Place the cursor in front of the v of vbYesNo and press backspace until you
get it on the same line as the another?",

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Graham Mayor

There's a donations link on my web site ;)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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