Solved

Save filename with timestamp

Posted on 2008-10-21
2
913 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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

744 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

18 Experts available now in Live!

Get 1:1 Help Now