Solved

Save filename with timestamp

Posted on 2008-10-21
2
915 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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 use a scrolling table in Microsoft Excel using the INDEX function.

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now