Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.newusers
jimc jimc is offline
external usenet poster
 
Posts: 1
Default VBA, FileCopy instead of save to Flash Drive?

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

  #2   Report Post  
Posted to microsoft.public.word.newusers
aalaan aalaan is offline
external usenet poster
 
Posts: 14
Default VBA, FileCopy instead of save to Flash Drive?

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.

"jimc" wrote in message
ups.com...
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



  #3   Report Post  
Posted to microsoft.public.word.newusers
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default VBA, FileCopy instead of save to Flash Drive?

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org




jimc wrote:
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



  #4   Report Post  
Posted to microsoft.public.word.newusers
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default VBA, FileCopy instead of save to Flash Drive?

I have added a version of this macro with improved error handling to my web
site http://www.gmayor.com/automatically_....htm#removable

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


Graham Mayor wrote:
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



jimc wrote:
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



  #5   Report Post  
Posted to microsoft.public.word.newusers
jimc jimc is offline
external usenet poster
 
Posts: 1
Default VBA, FileCopy instead of save to Flash Drive?

Graham Mayor wrote:
I have added a version of this macro with improved error handling to my web
site http://www.gmayor.com/automatically_....htm#removable


snip...
Thank you Graham.

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to save word 2003 on mapped drive JennyY Microsoft Word Help 1 February 14th 07 07:31 PM
Can't Save A File On A USB Drive Ralph K. Park Microsoft Word Help 3 December 21st 06 11:59 AM
Why is it not letting me save to E:/ drive? Jules Microsoft Word Help 3 October 22nd 05 08:52 PM
Can Not Save Word Docs on Network Drive Wayne New Users 1 January 21st 05 12:34 AM
access to my CD drive to save files Alan S Microsoft Word Help 3 January 12th 05 10:00 PM


All times are GMT +1. The time now is 03:23 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"