Saving filename with date and time

  reddwarfcrew 10:46 15 Apr 2005
Locked

I'm looking for a bit of VB code to be able to save a document with the name being the date and time it was saved:

Can anyone help with what I need to put where it says 'code here'.

Thanks



ActiveDocument.SaveAs FileName'code here',


FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="",


AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False,


EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False,


SaveFormsData:=False, SaveAsAOCELetter:= _
False

  VoG II 10:55 15 Apr 2005

Found click here - any use?

  reddwarfcrew 11:05 15 Apr 2005

but it doesn't seem to work, I get the error:


Compile error:

Type-declaration character does not match declared data type.

  VoG II 11:13 15 Apr 2005

Sub tst()


Dim pFileName As String

pFileName = Options.DefaultFilePath(wdDocumentsPath)

If Right$(pFileName, 1) <> "\" Then

pFileName = pFileName & "\"

End If

pFileName = pFileName & "MyFile" & Format$(Now, "yy-mm-dd")

ActiveDocument.SaveAs FileName:=pFileName

End Sub

Works for me. Try taking out the options (SaveNativePictureFormat:=False etc.) one at a time to see which is causing the error.

  VoG II 11:15 15 Apr 2005

Sub tst()

Dim pFileName As String

pFileName = Options.DefaultFilePath(wdDocumentsPath)

If Right$(pFileName, 1) <> "\" Then

pFileName = pFileName & "\"

End If

pFileName = pFileName & "MyFile" & Format$(Now, "yy-mm-dd")

ActiveDocument.SaveAs FileName:=pFileName

End Sub

Also, in the Visual Basic Editor Debug/Compile and see if it finds any errors.

  reddwarfcrew 11:21 15 Apr 2005

It just doesn't work for me even if I copy and paste your code.

When it errors it highlights the format$

  VoG II 11:42 15 Apr 2005

Curious...

Try

pFileName = pFileName & "MyFile" & Format(Now, "yy-mm-dd")

  reddwarfcrew 11:50 15 Apr 2005

been trying that, I then get a message saying invalid number of arguments!

  VoG II 11:55 15 Apr 2005

pFileName = pFileName & "MyFile" & Format(Now, "yy-mm-dd", vbSunday, vbFirstJan1)

  reddwarfcrew 11:58 15 Apr 2005

wrong number of arguments or invalid property assignment

Arrghhhh

I'm so close to doing what I want, but also so far!

  reddwarfcrew 12:00 15 Apr 2005

ActiveDocument.SaveAs FileName:=UserForm1.account.Value & Date & Time

but it failed as the default date format is dd/mm/yy and '/'s aren't allowed in the filename!

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

AMD Radeon Adrenalin release date, new features, compatible graphics cards

Inside the iMac Pro - Apple's most powerful Mac yet

iMac Pro release date, UK price & specs

Comment nettoyer Windows et optimiser son PC gratuitement ?