TelMaco
asked on
Save filename with timestamp
This needs to run as a schedualled task:
This code works while logged on:
Sub Original_Create_and_Send()
On Error Resume Next
Application.DisplayAlerts = False
'opens Word template
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Applica tion")
wrdApp.Visible = False 'hides MS word
Set wrdDoc = wrdApp.Documents.Open("C:\ Reports\Te mplate.doc ")
'copy to Word
Sheets("Final Report").Select
Range("A1:G45").CopyPictur e ' creates report as a bitmap
wrdApp.Selection.Paste
Application.CutCopyMode = False
'Save word
Dim sFileName As String, sPath As String
sPath = "C:\Reports\Archive\" 'change path here if you want
'adds a timestamp to the file name
sFileName = "VoIP Status " & Format(Now(), "mm_dd_yyyy hh mm AMPM")
wrdDoc.SaveAs (sPath & sFileName)
But it does NOT work while logged off
If I change this:
sFileName = "VoIP Status " & Format(Now(), "mm_dd_yyyy hh mm AMPM")
To this:
sFileName = "VoIP Status "
It DOES work while logged off
So why is the
& Format(Now(), "mm_dd_yyyy hh mm AMPM")
Part not working while logged off??
Thank you!!
This code works while logged on:
Sub Original_Create_and_Send()
On Error Resume Next
Application.DisplayAlerts = False
'opens Word template
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Applica
wrdApp.Visible = False 'hides MS word
Set wrdDoc = wrdApp.Documents.Open("C:\
'copy to Word
Sheets("Final Report").Select
Range("A1:G45").CopyPictur
wrdApp.Selection.Paste
Application.CutCopyMode = False
'Save word
Dim sFileName As String, sPath As String
sPath = "C:\Reports\Archive\" 'change path here if you want
'adds a timestamp to the file name
sFileName = "VoIP Status " & Format(Now(), "mm_dd_yyyy hh mm AMPM")
wrdDoc.SaveAs (sPath & sFileName)
But it does NOT work while logged off
If I change this:
sFileName = "VoIP Status " & Format(Now(), "mm_dd_yyyy hh mm AMPM")
To this:
sFileName = "VoIP Status "
It DOES work while logged off
So why is the
& Format(Now(), "mm_dd_yyyy hh mm AMPM")
Part not working while logged off??
Thank you!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Anyways,
Why does it not require the "& ".Doc"" if I am logged on ?!?!?
In any case it works like a charm now. Thank you thank you thank you!!
Stephen