Using a Macro to do a Save As

D

dherrig

I have the name I want to use as a file name already in the document. I want
to copy this and paste it into the Save as File name window using a macro. I
have recorded the macro but instead of putting in the file name window the
code to use the copied file name it pastes into the macro the name of the
file I was using when recording the macro so every file is saved with that
name instead of the newly copied name. What code do I need in place of
XXXX.doc to make this work?

ActiveDocument.SaveAs FileName:="XXXX.doc", FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False

Thanks
Dave
 
S

Suzanne S. Barnhill

If you put the information into the Title document property, it will be
proposed as the default filename in Save As.
 
B

Beth Melton

If you want to simply select the text to use for the file name then
something like this may work:

Dim strFName As String
strFName = Selection.Range
strFName = Replace(Trim(strFName), Chr(13), "")
ActiveDocument.SaveAs FileName:=strFName

Note I accommodated the possibility of spaces at the beginning/end and
paragraph marks in the selection but depending on other
leading/trailing characters you may select you could encounter errors.
If you do just add another Replace function to remove them.

Please post all follow-up questions to the newsgroup. Requests for
assistance by email can not be acknowledged.

~~~~~~~~~~~~~~~
Beth Melton
Microsoft Office MVP

Word FAQ: http://mvps.org/word
TechTrax eZine: http://mousetrax.com/techtrax/
MVP FAQ site: http://mvps.org/
 
D

dherrig

Sorry I am a beginner in using scripts so I have no idea how what you have
sent would be used.

I already have the macro running to the point of copying the file name out
of the document. the next step I need is to open up the Save as dialog box (
I normally use the F12 key) and then paste the copied file name into the File
Name window.
 
B

Beth Melton

Just copy/paste the code I provided in my post and replace it with
what you copy/pasted for us to take a look at. IOW, in your macro
between Sub...End Sub you should paste the code.

The macro will pick up text you have selected and use it your file
name. Note it will by-pass the Save As dialog.

Please post all follow-up questions to the newsgroup. Requests for
assistance by email can not be acknowledged.

~~~~~~~~~~~~~~~
Beth Melton
Microsoft Office MVP

Word FAQ: http://mvps.org/word
TechTrax eZine: http://mousetrax.com/techtrax/
MVP FAQ site: http://mvps.org/
 

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