Editing the creation date in visual basic

J

Jelly Belly

Hello, first question, but I've been lurking for a while. This is a great
resource for people learning how to code by the way.

We receive an email every day and I've set up a VB script to run that saves
the file with the creation date in the file name. The problem is the
creation date is T+1 the actual date of the attached file. For example the
script will save a file with 08.17.07 in the file name, but I actually want
08.16.07.

Is there a way to edit the code to name the file with the creation date -1
day to properly name the file?

Thanks a lot
 
J

Jelly Belly

By the way, this is the code I'm using, gleaned from this very helpful
website http://www.fontstuff.com/outlook/oltut01.htm

Sub JellySwaps(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim atmt As Attachment
Dim date as string

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
Set date = format(olmail.creationtime, "mm.dd "

MsgBox olMail.Subject
For Each atmt In olMail.Attachments
FileName = "C:\test\" & _
date & "jelly.pdf"
atmt.SaveAsFile FileName

Next atmt

Set olMail = Nothing
Set olNS = Nothing
End Sub
 
K

Ken Slovak - [MVP - Outlook]

The best place for programming questions is one of the developer groups such
as program_vba, down the hall.

You can't change the CreationTime property, that's read-only to your code.
You can get item.CreationTime and use the DateAdd method to add 1 day to the
date you get back. Use the Help to look up the syntax for the DateAdd
method.
 
J

Jelly Belly

Hi Ken, I used the Dateadd method to subtract a day from the creation date
and populate file name, thanks for pointing me in the right direction.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top