Solved

Save filename with timestamp

Posted on 2008-10-21
2
916 Views
Last Modified: 2012-05-05
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.Application")
    wrdApp.Visible = False 'hides MS word
    Set wrdDoc = wrdApp.Documents.Open("C:\Reports\Template.doc")

    'copy to Word
    Sheets("Final Report").Select
    Range("A1:G45").CopyPicture ' 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!!
0
Comment
Question by:TelMaco
2 Comments
 
LVL 59

Accepted Solution

by:
Saurabh Singh Teotia earned 500 total points
ID: 22769993
Replace this line....

sFileName = "VoIP Status " & Format(Now(), "mm_dd_yyyy hh mm AMPM")

With this...

sFileName = "VoIP Status " & Format(Now(), "mm_dd_yyyy hh mm AM/PM") &".xls"

Saurabh...
0
 

Author Comment

by:TelMaco
ID: 22770346
One note - It's a Word File, so  it's : & ".Doc"

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
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question