Auto-saving Word backup to a DIFFERENT folder

M

Marv Wolfman

As a default, Word saves a backup file to the SAME folder as the
original. I want to automatically have it save to a BACKUP folder
instead. Here is my reason: I have .Mac which does an automatic daily
update. Since I use Word in many different folders, depending on what
I'm writing, if I wanted to save everything it would come to 300M, but
..Mac only gives 100M as backup space. I don't want to buy more space.
So I want to create a Backup file and have that only backup to .Mac
every night. I already have my other writing files saved onto CD and
DVD so I really don't need everything saved. Is there any way to
change the Word default so it will automatically save a backup to a
specially marked folder instead of the filder that the original file
is in. Thank you.
 
J

J.E. McGimpsey

As a default, Word saves a backup file to the SAME folder as the
original. I want to automatically have it save to a BACKUP folder
instead. Here is my reason: I have .Mac which does an automatic daily
update. Since I use Word in many different folders, depending on what
I'm writing, if I wanted to save everything it would come to 300M, but
.Mac only gives 100M as backup space. I don't want to buy more space.
So I want to create a Backup file and have that only backup to .Mac
every night. I already have my other writing files saved onto CD and
DVD so I really don't need everything saved. Is there any way to
change the Word default so it will automatically save a backup to a
specially marked folder instead of the filder that the original file
is in. Thank you.

AFAIK, there's no built-in way to do this.

Here's one way. Put this in a global template. It will replace your
File/Save command.

The built-in Save command calls Save As the first time the document
is saved. Unfortunately, Word v.X has a bug that prevents using the
normal File/SaveAs dialog - VBA doesn't wait for the user to click
on Save or Cancel (it's actually an OSX dialog called by Word), so
you have a choice of entering the initial filename via a
inputbox/userform, or telling the user to use Save As the first time
the document is saved. For this purpose, I chose the latter route.
This means that the backup will not occur on the initial save.

Modify the Constants as desired for your path, and the
prefix/extension. As written, a file saved as either "hello" or
"hello.doc" will be saved in the backup folder as "Backup of
hello.doc". I limited the filename to 31 characters. Hopefully, some
day, that restriction will no longer be necessary.

'Put this in a global template to replace the built-in
'Save command
Public Sub FileSave()
'J.E. McGimpsey
Const BKUPPATH As String = _
"Macintosh HD:Users:je:Documents:Backups:"
Const PRESTR As String = "Backup of "
Const XTNSN As String = ".doc"
Const MAXNAMELEN As Long = 31&
Dim svName As String
Dim bkName As String
Dim lenName As Long
Dim maxChars As Long
Dim oldSaveProperties As Boolean
Dim oldBackup As Boolean

With ActiveDocument
'Can't use wdDialogFileSaveAs in OS X due to bug!
'So have to punt on first save of document
If .Name = .FullName Then
MsgBox Prompt:= _
"Please save the document using ""Save As""", _
Buttons:=vbOKOnly, _
Title:="FileSave with Backup"
Else
'Already saved once
svName = .FullName
bkName = PRESTR & .Name
lenName = Len(bkName)
'Limit filename to MAXNAMELEN characters.
maxChars = MAXNAMELEN - Len(XTNSN)
'Strip any existing extension and add XTNSN
bkName = BKUPPATH & Left(Left(bkName, lenName + _
4 * (Mid(bkName, lenName - 3, 1) = ".")), _
maxChars) & XTNSN
'bypass SaveProperties and CreateBackup preferences
With Options
oldSaveProperties = .SavePropertiesPrompt
.SavePropertiesPrompt = False
oldBackup = .CreateBackup
.CreateBackup = False
End With
Application.DisplayAlerts = False
'Must save backup first, then document, or
'the backup will be the open file.
.SaveAs FileName:=bkName, AddToRecentFiles:=False
.SaveAs FileName:=svName
Application.DisplayAlerts = True
'Restore user preferences
With Options
.SavePropertiesPrompt = oldSaveProperties
.CreateBackup = oldBackup
End With
End If
End With
End Sub


Note that this is pretty bare-bones - no error checking, no format
options, etc.
 
B

Beth Rosengard

AFAIK, there's no built-in way to do this.

Here's one way. Put this in a global template. It will replace your
File/Save command.

The built-in Save command calls Save As the first time the document
is saved. Unfortunately, Word v.X has a bug that prevents using the
normal File/SaveAs dialog - VBA doesn't wait for the user to click
on Save or Cancel (it's actually an OSX dialog called by Word), so
you have a choice of entering the initial filename via a
inputbox/userform, or telling the user to use Save As the first time
the document is saved. For this purpose, I chose the latter route.
This means that the backup will not occur on the initial save.

Modify the Constants as desired for your path, and the
prefix/extension. As written, a file saved as either "hello" or
"hello.doc" will be saved in the backup folder as "Backup of
hello.doc". I limited the filename to 31 characters. Hopefully, some
day, that restriction will no longer be necessary.
<snip>

I'm thinking that Mark may just possibly be using Office 98. I say that
because, beginning with Word 2001, the Save As default behavior changed. In
Office 98, Word did indeed save a document to the "folder that the original
file is in." In Word 2001/Word X, however, doing a Save As will put the
document in whatever folder was last navigated to in the Save dialog ­ which
may or may not be the folder the original document was in.

Mark, please always state your OS and Word/Office version numbers when
posting! If you're not in Word X, J.E.'s macro may not work for you. (I
don't "do" macros, so I can't be sure.) If that's the case, post back.

--
Beth Rosengard
Mac MVP

Mac Word FAQ: <http://www.mvps.org/word/FAQs/WordMac/index.htm>
Entourage Help Page: <http://www.entourage.mvps.org/toc.html>
 
J

J.E. McGimpsey

Beth Rosengard said:
I'm thinking that Mark may just possibly be using Office 98. I say that
because, beginning with Word 2001, the Save As default behavior changed. In
Office 98, Word did indeed save a document to the "folder that the original
file is in." In Word 2001/Word X, however, doing a Save As will put the
document in whatever folder was last navigated to in the Save dialog ­ which
may or may not be the folder the original document was in.

I don't think that's an issue with my macro - the first time Save is
called, the macro punts, and requests the user use SaveAs instead.
SaveAs may navigate to a different location, but that doesn't affect
subsequent saves - once saved, the document will be saved back to
wherever the document resides (since I get the existing path at the
start of the macro and use that to write the file out), and the
backup goes to a different folder entirely.
Mark, please always state your OS and Word/Office version numbers when
posting! If you're not in Word X, J.E.'s macro may not work for you. (I
don't "do" macros, so I can't be sure.) If that's the case, post back.

Second that! It's been so long since I've done anything other than
testing in Office98 that I no longer remember specifics. I tend to
write macros for the most limiting version - with dialogs, that's
Word v.X.

"Doing macros" need not be arduous - though this one took me a bit
of playing around to get right, to the extent that it is. I still
probably only understand one tenth of the Word Object Model, and I
can make Word do amazing things
 
M

Matthew Centurión [MS]

Hey J.E., neat little script. Could you explain exactly what you were trying
to do with the SaveAs dialog that didn't work for you.

Also, here's a modification that will do what I think you wanted on first
save:

'Put this in a global template to replace the built-in
'Save command
Public Sub FileSave()
'J.E. McGimpsey
Const BKUPPATH As String = _
"Macintosh HD:Users:je:Documents:Backups:"
Const PRESTR As String = "Backup of "
Const XTNSN As String = ".doc"
Const MAXNAMELEN As Long = 31&
Dim svName As String
Dim bkName As String
Dim lenName As Long
Dim maxChars As Long
Dim oldSaveProperties As Boolean
Dim oldBackup As Boolean

With ActiveDocument
If .Name = .FullName Then
On Error GoTo SaveError
.Save
End If

'Already saved once
svName = .FullName
bkName = PRESTR & .Name
lenName = Len(bkName)
'Limit filename to MAXNAMELEN characters.
maxChars = MAXNAMELEN - Len(XTNSN)
'Strip any existing extension and add XTNSN
bkName = BKUPPATH & Left(Left(bkName, lenName + _
4 * (Mid(bkName, lenName - 3, 1) = ".")), _
maxChars) & XTNSN
'bypass SaveProperties and CreateBackup preferences
With Options
oldSaveProperties = .SavePropertiesPrompt
.SavePropertiesPrompt = False
oldBackup = .CreateBackup
.CreateBackup = False
End With
Application.DisplayAlerts = False
'Must save backup first, then document, or
'the backup will be the open file.
.SaveAs FileName:=bkName, AddToRecentFiles:=False
.SaveAs FileName:=svName
Application.DisplayAlerts = True
'Restore user preferences
With Options
.SavePropertiesPrompt = oldSaveProperties
.CreateBackup = oldBackup
End With
End With
SaveError:
End Sub


Matt
MacWord Testing
Macintosh Business Unit

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Please do not send email directly to this e-mail address. It is for
newsgroup purposes only.

Find out everything about Microsoft Mac Newsgroups at:
http://www.microsoft.com/mac/support/newsgroups.asp
Check out product updates and news & info at:
http://www.microsoft.com/mac
 
J

J.E. McGimpsey

Matthew Centurion said:
Hey J.E., neat little script. Could you explain exactly what you were trying
to do with the SaveAs dialog that didn't work for you.

Hi Matt - Nice workaround - thanks!

Based on Word2001 (where it works fine) and internal Word v.X
dialogs (as opposed to ones provided by the OS) here's what I would
have expected to work:

Const SVBTN As Long = -1
If .Name = .FullName Then
'Make sure user finished dialog with Save button
If Not Dialogs(wdDialogFileSaveAs).Show = SVBTN Then _
Exit Sub
svName = .Name
Else
svName = .FullName
End If

The code displays the dialog, but immediately falls through,
throwing an error at the first .Save As

What's ironic to me is that the error received is:

*****
Run-time error '4605':

The SaveAs method or property is not available because the document
is in a modal state.
******

Best guess is that someone forgot to tell the FileSaveAs dialog's
..Show (and .Display) methods what "modal" means.

Mac OS X 10.2.6 (6L60), Word 10.1.4 (070301)
 
J

John McGhie [MVP]

Never likely to: VBA is going away, on both PC and Mac, soon. So we'll get
fixes to AppleScript, but not VBA.

Cheers


This responds to article <[email protected]>,
from "KMFAV said:
"Matthew Centurión [MS]" said ...
Const MAXNAMELEN As Long = 31&

When will we see a fix for THAT?

Thanks,
k

--
All Spam and attachments blocked by Microsoft Entourage for Mac OS X. Please
post replies to the newsgroup to maintain the thread.

John McGhie, Microsoft MVP: Word for Macintosh and Word for Windows
Consultant Technical Writer <[email protected]>
+61 4 1209 1410; Sydney, Australia: GMT + 10 hrs
 

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