Quickly insert file name and file path or other information into cell, header or footer in Excel Sometimes, we may need to inserting current Excel file (workbook) name, the file saving path and worksheet name in a cell, header or footer in Excel, generally, we handle it by uesing formulas. Save a File to the Destop with VBA. The following is a simple example of copying data from the current workbook and saving it to the desktop. The procedure will then save the file and close it leaving the user on the original sheet.
Save E-mail attachments to folder
Important read this :
The code on this page is only working when you use Outlook as your mail program.
Copy the code in a Standard module of your workbook, if you just started with VBA see this page.
Where do I paste the code that I find on the internet
Copy the code in a Standard module of your workbook, if you just started with VBA see this page.
Where do I paste the code that I find on the internet
Read this good
If you receive a lot of mail with attachments and you want to save the files in a folder on your computer then you can use the code on this page to save the files in the folder you want.
First right click on the Inbox and choose New Folder, in the code example I use the name 'MyFolder'. Note: look good the folder MyFolder must be inside your Inbox folder
First right click on the Inbox and choose New Folder, in the code example I use the name 'MyFolder'. Note: look good the folder MyFolder must be inside your Inbox folder
Tip: Create a mail rule in Outlook (Tools>Rules and Alerts) and move the mail from ? or with the
subject ? to the folder in your Inbox named 'MyFolder' when the mail arrived.
Note: You can also move the files from your Inbox to the folder 'MyFolder' manual.
To test the code copy a few mails into the new folder named MyFolder inside your Inbox folder.
subject ? to the folder in your Inbox named 'MyFolder' when the mail arrived.
Note: You can also move the files from your Inbox to the folder 'MyFolder' manual.
To test the code copy a few mails into the new folder named MyFolder inside your Inbox folder.
Macro example
We use two macros in this example but we only run the macro named Test with one code line.
There are the three arguments in the macro call in the Test macro :
Arg 1 = Folder name of folder inside your Inbox
Arg 2 = File extension, ' is every file
Arg 3 = Save folder, 'C:UsersRontest' or '
If you use ' it will create a date/time stamped folder for you in your 'Documents' folder
Note: If you use this 'C:UsersRontest' the folder must exist.
This will copy all files from “MyFolder” to a new folder in the Documents folder
SaveEmailAttachmentsToFolder 'MyFolder', ', '
This will copy all xls files from “MyFolder” to 'C:UsersRontest'
SaveEmailAttachmentsToFolder 'MyFolder', 'xls', 'C:UsersRontest'
This will copy all xlsx files from “MyFolder” to 'C:UsersRontest'
SaveEmailAttachmentsToFolder 'MyFolder', 'xlsx', 'C:UsersRontest'
Set a reference to Outlook and copy/paste the code in a standard module
1) Go to the VBA editor, Alt -F11
2) Tools>References in the Menu bar
3) Place a Checkmark before Microsoft Outlook ? Object Library
? is the Outlook version number
4) Insert>Module
5) Paste the code (two macros) in this module
6) Alt q to close the editor
7) Save the file
There are the three arguments in the macro call in the Test macro :
Arg 1 = Folder name of folder inside your Inbox
Arg 2 = File extension, ' is every file
Arg 3 = Save folder, 'C:UsersRontest' or '
If you use ' it will create a date/time stamped folder for you in your 'Documents' folder
Note: If you use this 'C:UsersRontest' the folder must exist.
This will copy all files from “MyFolder” to a new folder in the Documents folder
SaveEmailAttachmentsToFolder 'MyFolder', ', '
This will copy all xls files from “MyFolder” to 'C:UsersRontest'
SaveEmailAttachmentsToFolder 'MyFolder', 'xls', 'C:UsersRontest'
This will copy all xlsx files from “MyFolder” to 'C:UsersRontest'
SaveEmailAttachmentsToFolder 'MyFolder', 'xlsx', 'C:UsersRontest'
Set a reference to Outlook and copy/paste the code in a standard module
1) Go to the VBA editor, Alt -F11
2) Tools>References in the Menu bar
3) Place a Checkmark before Microsoft Outlook ? Object Library
? is the Outlook version number
4) Insert>Module
5) Paste the code (two macros) in this module
6) Alt q to close the editor
7) Save the file
Note: You not have to change the code in the macro below. But you can change Item.SenderName to ReceivedTime in the save line like Format(Item.ReceivedTime, 'yyyy-mmm-dd')
When you do that it will put the ReceivedTime before each file name instead of the SenderName