PDA

View Full Version : Solved: Auto save on Open



Scooter172
11-29-2010, 10:47 PM
I have some Word demplates (DOTM) that when opened I want them to be named and saved with the current date to a specified folder. I have this ability in Xcel. However this routine does not work in Word. the path would be H:\LRT\RCCDailyOpsLogs\"document name MM-DD-YY DDD".Docx. Any help on this would be great. since this is a dotm I cannot upload it here.

Scooter172
11-30-2010, 12:53 AM
ChangeFileOpenDirectory "H:\LRT\RCCDailyOpsLogs\"
ActiveDocument.SaveAs FileName:="H:\LRT\RCCDailyOpsLogs\Vikings Game Summary.docx", _
FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False[quote=Scooter172]I have some Word demplates (DOTM) that when opened I want them to be named and saved with the current date to a specified folder. How do I add the date in this format to the end of the name in this code.. I want the format to be as follows MM-DD-YY DDD

:)

Tinbendr
11-30-2010, 06:20 AM
In the ThisDocument module:

Private Sub Document_New()
Dim MyPath As String

MyPath = "H:\LRT\RCCDailyOpsLogs\"
ChangeFileOpenDirectory MyPath
ActiveDocument.SaveAs FileName:=MyPath & "Vikings Game Summary " & _
Format(Date, "mm/dd/yyyy ddd") & ".docx", _
FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False
End Sub

David

fumei
11-30-2010, 09:52 AM
Why do you need to change the path? There is no need to change the path.

Private Sub Document_New()
Dim MyPath As String

MyPath = "H:\LRT\RCCDailyOpsLogs\"
ActiveDocument.SaveAs FileName:=MyPath & "Vikings Game Summary " & _
Format(Date, "mm/dd/yyyy ddd") & ".docx", _
FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False
End Sub
Unless there is some need (beyond what was asked for) do not change the path.

Scooter172
11-30-2010, 05:28 PM
In the ThisDocument module:

Private Sub Document_New()
Dim MyPath As String

MyPath = "H:\LRT\RCCDailyOpsLogs\"
ChangeFileOpenDirectory MyPath
ActiveDocument.SaveAs FileName:=MyPath & "Vikings Game Summary " & _
Format(Date, "mm/dd/yyyy ddd") & ".docx", _
FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False
End Sub

David

I tried both of these and both failed siting bad file names or invalid file name. Will continue to work at it.. :devil2:

Scooter172
11-30-2010, 05:32 PM
Why do you need to change the path? There is no need to change the path.

Private Sub Document_New()
Dim MyPath As String

MyPath = "H:\LRT\RCCDailyOpsLogs\"
ActiveDocument.SaveAs FileName:=MyPath & "Vikings Game Summary " & _
Format(Date, "mm/dd/yyyy ddd") & ".docx", _
FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False
End Sub
Unless there is some need (beyond what was asked for) do not change the path.

This did not work.. siting bad file name.

Scooter172
11-30-2010, 06:54 PM
The file path needs to change as the template is kept in a templates folder but the operating folder is different.

Tinbendr
11-30-2010, 07:19 PM
Sorry, You can't have the forward slash in the filename.

ActiveDocument.SaveAs FileName:=MyPath & "Vikings Game Summary " & _
Format(Date, "mm_dd_yyyy ddd") & ".docx"

Scooter172
11-30-2010, 07:58 PM
Thanks That did it!!! Thanks

fumei
12-01-2010, 09:48 AM
Did not even look at that. Ooops.