macro questions

M

matt101

Hello,

I posted yesterday requiring help creating a backup procedure to which
Suzanne S. Barnhill pointed me in the right direction - thank you!
Now I have two questions on a macro I created which I think should be
addressed in a new post. I have copied the macro below, and wonder if
its possible to replace the inputbox with code which will automatically
save the document with the current date? Failing this, the 'cancel'
button on the inputbox window results in an error - could anyone help
me tidy this up?

Thank you

Sub SaveAs()
ChangeFileOpenDirectory _
"\\servername\folder name"
strDocName = InputBox("Enter document name.")
ActiveDocument.SaveAs FileName:=strDocName, _
FileFormat:=wdFormatDocument _
, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False,
SaveAsAOCELetter:= _
False
End Sub
 
M

matt101

Hello Graham,

When the macro is run, I would like the new file to be saved with th
name being the current date, so I wondered if there is some sort o
function for that? If the macro is run more than once on the same da
and the file is overwritten, then that is fine, but when run for th
first time in a day, a new file should be created with that day'
date.

Thanks
 
G

Graham Mayor

On your head be it!

Sub MySaveAs()
'this will overwrite the previous file of
'the same name without prompting each time
'the macro is used.
Dim strPath As String
Dim strDocName As String
strPath = "\\servername\folder name\"
strDocName = Format(Date, "d MMM yyyy") & ".doc"
ActiveDocument.SaveAs FileName:=strPath & strDocName, _
FileFormat:=wdFormatDocument
End Sub

Change the path and the date format to taste.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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