Solved

Renaming Outlook CSV Detachments

Posted on 2011-09-28
7
221 Views
Last Modified: 2013-02-15
Hello Experts.  I am a newbie and trying to resolve this issue:

I am trying to create a file name for csv attachments that I am saving on the network.  

The format that I want to save the files is:

ReceivedTime less 1 day, formatted ddmmyyyy plus the file name

example:

file ABCDEF.CSV arrived today,  28 September, so the file saved with yesterdays date:

H:\\FOLDER1\FOLDER2\27092011 ABCDEF.CSV

Whilst I can get the file to detach and save, I am struggling to get the file name  correct file name.

I will be very grateful your help.


0
Comment
Question by:MagicMoggy
  • 3
  • 2
7 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 36730966
Hi, I think you'll be after something like this.

Regards,

Rob.
strFolder = "H:\FOLDER1\FOLDER2\"
If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"

'....attach to your inbox and then go through the messages

For Each Item In Inbox.Items
	strTimeReceived = objMessage.TimeReceived
	dteYesterday = DateAdd("d", -1, CDate(strTimeReceived))
	strDate = Right("0" & Day(dteYesterday), 2) & Right("0" & Month(dteYesterday), 2) & Year(dteYesterday)
	For Each Atmt In Item.Attachments
		strFilePath = strFolder & strDate & " " & Atmt.FileName
		Atmt.SaveAsFile strFilePath
	Next
Next

Open in new window

0
 

Accepted Solution

by:
MagicMoggy earned 0 total points
ID: 36815789
Ron, thank you for your speedy reply.  I did have trouble with line 8, and after much time I realised that the solution was to simply knock off the value of 1 from the RecceivedTime, ensuring that the ((olkMessage.ReceivedTime - 1) was entered in brackets, (otherwise it did not deduct the value of 1).

'olkmessage as outlook mailitem,
              strDate = Strings.Format((olkMessage.ReceivedTime - 1), "ddmmyyyy") & " "
               strFilename = strDate & strFilename
               olkAttachment.SaveAsFile strRootFolderPath & strFilename

Again many thanks for your help.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36818568
>> Strings.Format

Does that means your code is .NET?

Anyway, is that solved then, or is there something else you need?

Regards,

Rob.
0
 

Author Comment

by:MagicMoggy
ID: 36890271
I am a complete novice, but I believe it is VBA!!

Regards
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36890982
OK.  I haven't seen that notation be able to be used in VBA, but if it works for you, then great!

I see you're new to EE.  Welcome!

Now if you have found your solution, you can select the comments that attributed to the answer, in order to close the question.

Thanks,

Rob.
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

Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

861 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

23 Experts available now in Live!

Get 1:1 Help Now