VBA, FileCopy instead of save to Flash Drive?

J

jimc

I am new to VBA, I have seen here and on other newsgroups that it is
unwise to save a word file directly to removeable media because of the
various temp files created. Can I use Filecopy on a closed file
instead? My snippet is below. I have used and modified the code from
Graham Mayors site (http://www.gmayor.com/index.htm):

Sub Backup()

Dim strFileA, strFileB, strFileC, strFileD
ActiveDocument.Save
strFileA = ActiveDocument.Name

' backup file to different folder every other day

If Even = (Day(Now) Mod 2) - 1 Then
strFileB = "C:\Documents and Settings\Jim.DELL5150\My
Documents\MyOddBackups\" & Format$(Now, "mmm d") & strFileA
Else
strFileB = "C:\Documents and Settings\Jim.DELL5150\My
Documents\MyEvenBackups\" & Format$(Now, "mmm d") & strFileA
End If

strFileC = ActiveDocument.FullName

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

' after closing backup file, copy it to USB flash drive

FileCopy strFileB, "F:\backups.doc"

End Sub
 
A

aalaan

Copying files outside Word is OK, and I have written a macro that does just
that using FileCopy. It is the Save operation from Word that is dangerous on
removable media. I may be wrong, being just a beginner, but that is my
understanding. I will soon get shot down if I'm wrong.
 
G

Graham Mayor

Yes you can use filecopy - I think the following is what you have attempted
to produce.

Sub Backup()
Dim strFileA As String
Dim strFileB As String
Dim strFlash As String
ActiveDocument.Save 'save the original

strFileA = ActiveDocument.Name 'saved original document name
strFlash = "F:\" & strFileA 'flash drive filename
' backup file to different folder every other day
If Even = (Day(Now) Mod 2) - 1 Then
strFileB = "C:\Documents and
Settings\Jim.DELL5150\MyDocuments\MyOddBackups\" & Format$(Now, "mmm d ") &
strFileA
Else
strFileB = "C:\Documents and
Settings\Jim.DELL5150\MyDocuments\MyEvenBackups\" & Format$(Now, "mmm d ") &
strFileA
End If
ActiveDocument.SaveAs FileName:=strFileB 'save in the appropriate folder
' after closing backup file, copy it to USB flash drive
ActiveDocument.Close 'close the document
On Error GoTo oops
FileCopy strFileA, strFlash 'Copy source to flash
Documents.Open strFileA
End
oops:
MsgBox "The copy drive is not available"
Documents.Open strFileA
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
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