Solved

Renaming Outlook CSV Detachments

Posted on 2011-09-28
7
209 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

20 Experts available now in Live!

Get 1:1 Help Now