View Full Version : Re: FileSaveAs macro


John McGhie [MVP - Word]
07-02-2003, 07:51 AM
Hi Sirius:

Yes, I know what you are doing wrong :-)

You are trying to use Word X! Sorry, all the File dialogs in Word X are
actually Apple OS X Finder Windows, and they are not addressable from VBA.

Instead, do not try to use the dialog. Supply your name directly from VBA:

Dim myName As String
myName = "My Special Document Name.Doc"
ActiveDocument.SaveAs myName

That seems to work (I can't be sure, because I am using a different version
of Word).

Cheers

This responds to microsoft.public.mac.office.word on Mon, 30 Jun 2003
22:43:16 -0700, Sirius Black <siriusblack76[at]hotmail.com>:

> I need a macro which will modify the File save As dialog to suggest a file
> name. The file name is generated from the text, and then I try to implement
> the macro with code like this:
>
> With dialogs(wdDialogFileSaveAs)
> .name = savedtext
> .show
> End with
>
> This code works in Office 2K for Windows. In Office X the dialog comes up
> empty, with just .doc as the suggested file name. But occasionally, the
> first time I run the routine it does work. Thereafter, never.
>
> Can anybody give me a clue what I'm doing wrong?

All Spam blocked with SpamNet: a free download from http://www.cloudmark.com/

Please post all comments to the newsgroup to maintain the thread.

John McGhie, Consultant Technical Writer
McGhie Information Engineering Pty Ltd
Sydney, Australia. GMT + 10 Hrs
+61 4 1209 1410, mailto:john[at]mcghie-information.com.au

John McGhie [MVP - Word]
07-03-2003, 04:19 AM
Hi Alan:

Yes, it will save to the Last Saved Location, which Word keeps track of. If
no save has occurred since Word was started, Word will use the Documents
location set in Preferences>File Locations.

Using another couple of lines of VBA, you can return the path of the
ActiveDocument and specify that in the Save As, which I suspect would be a
safer strategy.

Try this: (be careful of the long lines: if you get compile errors, you have
wrapped a line).

Sub Macro2()
'
' Macro2 Macro
' Macro Written July 3 2003 by John McGhie
'
Dim myName As String
Dim myPath As String
Dim docName As String

docName = InputBox("Please enter the file name for the document.")

myPath = ActiveDocument.Path
If myPath = "" Then
myPath = Options.DefaultFilePath(wdDocumentsPath)
End If

myName = myPath & Application.PathSeparator & docName

ActiveDocument.SaveAs myName

End Sub

Please note: I did not have time to test that code on the Mac, you may have
to fiddle with it to get it to work. If the user has a never-saved document
open, its Path should come back blank. On the Mac, I am not sure that that
is the case. Also, I am not entirely sure that the Options object is
available on the Mac. If it is not, you will have to supply a default file
path.

Hope this helps

This responds to microsoft.public.mac.office.word on Wed, 02 Jul 2003
00:56:00 -0700, Alan Cairns <alancairns[at]dccnet.com>:

> Thanks. I think that will work. I trust it will save to the default
> directory. The VBA help file does say you can modify the dialogs, but it
> really doesn't give a good example.
> I'll try it your way.
>
> Sirius
>
> On 01/07/2003 11:51 PM, in article
> vhv4gvkh8mmk1cmjg3icn5jk2l4guhcjdr[at]4ax.com, "John McGhie [MVP - Word]"
> <john[at]mcghie-information.com.au> wrote:
>
> > Hi Sirius:
> >
> > Yes, I know what you are doing wrong :-)
> >
> > You are trying to use Word X! Sorry, all the File dialogs in Word X are
> > actually Apple OS X Finder Windows, and they are not addressable fromVBA.
> >
> > Instead, do not try to use the dialog. Supply your name directly from VBA:
> >
> > Dim myName As String
> > myName = "My Special Document Name.Doc"
> > ActiveDocument.SaveAs myName
> >
> > That seems to work (I can't be sure, because I am using a different version
> > of Word).
> >
> > Cheers
> >
> > This responds to microsoft.public.mac.office.word on Mon, 30 Jun 2003
> > 22:43:16 -0700, Sirius Black <siriusblack76[at]hotmail.com>:
> >
> >> I need a macro which will modify the File save As dialog to suggest a file
> >> name. The file name is generated from the text, and then I try to implement
> >> the macro with code like this:
> >>
> >> With dialogs(wdDialogFileSaveAs)
> >> .name = savedtext
> >> .show
> >> End with
> >>
> >> This code works in Office 2K for Windows. In Office X the dialog comes up
> >> empty, with just .doc as the suggested file name. But occasionally, the
> >> first time I run the routine it does work. Thereafter, never.
> >>
> >> Can anybody give me a clue what I'm doing wrong?
> >
> > All Spam blocked with SpamNet: a free download from http://www.cloudmark.com/
> >
> > Please post all comments to the newsgroup to maintain the thread.
> >
> > John McGhie, Consultant Technical Writer
> > McGhie Information Engineering Pty Ltd
> > Sydney, Australia. GMT + 10 Hrs
> > +61 4 1209 1410, mailto:john[at]mcghie-information.com.au

All Spam blocked with SpamNet: a free download from http://www.cloudmark.com/

Please post all comments to the newsgroup to maintain the thread.

John McGhie, Consultant Technical Writer
McGhie Information Engineering Pty Ltd
Sydney, Australia. GMT + 10 Hrs
+61 4 1209 1410, mailto:john[at]mcghie-information.com.au

Alan Cairns
07-03-2003, 08:28 AM
Thanks again. I've been working on your suggestion, and it works. I'm
getting more ambitious. I'm developing a user form to show the default
directory and the options in a drop down list. I need to ensure also that
there isn't already a file of that name in the directory.

This is turning into quite a project, and all because I can't get access to
the Word FileSaveAs, but rather an OSX version.

Alan

On 02/07/2003 8:19 PM, in article
6g17gv85oo7nm1j49b6q50t0jq5tplodar[at]4ax.com, "John McGhie [MVP - Word]"
<john[at]mcghie-information.com.au> wrote:

> Yes, it will save to the Last Saved Location, which Word keeps track of. If
> no save has occurred since Word was started, Word will use the Documents
> location set in Preferences>File Locations.
>
> Using another couple of lines of VBA, you can return the path of the
> ActiveDocument and specify that in the Save As, which I suspect would be a
> safer strategy.
>
> Try this: (be careful of the long lines: if you get compile errors, you have
> wrapped a line).
>
> Sub Macro2()
> '
> ' Macro2 Macro
> ' Macro Written July 3 2003 by John McGhie
> '
> Dim myName As String
> Dim myPath As String
> Dim docName As String
>
> docName = InputBox("Please enter the file name for the document.")
>
> myPath = ActiveDocument.Path
> If myPath = "" Then
> myPath = Options.DefaultFilePath(wdDocumentsPath)
> End If
>
> myName = myPath & Application.PathSeparator & docName
>
> ActiveDocument.SaveAs myName
>
> End Sub