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.
<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>
> 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
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
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
On 9/11/03 1:18 AM, in article
jemcgimpsey-6385...@msnews.microsoft.com, "J.E. McGimpsey"
<jemcg...@mvps.org> wrote:
> 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)
When will we see a fix for THAT?
Thanks,
k
Cheers
This responds to article <123e41cc.03091...@posting.google.com>,
from "KMFAV" <km...@yahoo.com> on 16/9/03 6:12 AM:
--
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 <jo...@mcghie-information.com.au>
+61 4 1209 1410; Sydney, Australia: GMT + 10 hrs