Paste content to Excel when .txt file (attachment) is opened

Status
Not open for further replies.

Nravota

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
Hi Guys,

I have a lot of emails with txt attachments that I need to handle every day. I select the message, open the attachement in notepad (without saving) and then manually paste it to excel workbook. I want to be able when I open the attachment that it is automatically loaded in this excel workbook. What I managed to do now is that when I save the file to my desktop I can open it from excel. But I want to do this with each opened txt file. Is there a way to do this in Outlook vba?

Sub ImportText()
Set myPlace = ActiveCell
Workbooks.OpenText _
Filename:=ActiveWorkbook.Path & "\MYFILE.txt", _
DataType:=xlDelimited, Tab:=True
ActiveSheet.UsedRange.Copy Destination:=myPlace
ActiveWorkbook.Close
End Sub
I want to trigger the macro each time I open txt file from Outlook. Can this be accomplished? Thank you very much in advance!
 
Triggering it when you open the attachment wouldn't be easy, there's no event in Outlook for that. Instead write a macro that saves the selected attachment (see ActiveExplorer.AttachmentSelection) to the hd, then use an adapted version of your Excel macro in Outlook to import the file.

To be able to use the Excel macro in Outlook, set a reference via Tools/References on "Microsoft Excel 14.0 Object Library". Here's a sample for how to open an Excel file from Outlook:
Open Excel File from within Outlook - VBOffice

Instead of ActiveCell use the Rn variable from the sample, and instead of ActiveWorkbook use Wb.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
H Macro to Copy Specific content from Mail Body and Paste to Excel Outlook VBA and Custom Forms 4
O How to paste website content using a specific font and removing URLs Using Outlook 2
O Copy email content and paste into new Word Document using a different font Using Outlook 1
K Copy Entire Email Content - Paste into new Task Outlook VBA and Custom Forms 2
J PSA: How to create custom keyboard shortcut for "Paste Unformatted Text" in Outlook on Windows Outlook VBA and Custom Forms 1
P Outlook 2016 Change Paste Special Default Format Using Outlook 8
P Can't paste an image into a task Using Outlook 3
P Add Paste Unformatted to QAT Using Outlook 1
B Paste formatted text (bold, underlined and in quotes) Outlook VBA and Custom Forms 1
J VBA Outlook : Subject line : Cut and Paste name to heading , number to very end of the body of Email Outlook VBA and Custom Forms 1
O Macro - paste as plain text Outlook VBA and Custom Forms 2
D Paste Excel table into Outlook message Outlook VBA and Custom Forms 6
D Outlook macro with today's date in subject and paste clipboard in body Outlook VBA and Custom Forms 1
K Paste from Windows Clipboard then change font without losing formatting Outlook VBA and Custom Forms 1
Stilgar Relsik Create a rule to copy text from an email and paste it in the subject line. Using Outlook 1
Diane Poremsky Paste clipboard contents using VBA Using Outlook 0
A Outlook: copy & paste Outlook VBA and Custom Forms 9
V Copy and paste body and subject and send multiple emails Outlook VBA and Custom Forms 3
G outlook 13 copy & paste without losing formatting Using Outlook 1
C Copy Cell value from Excel and paste into current email Outlook VBA and Custom Forms 10
R Copy/paste mailing address Outlook 2013 Using Outlook 6
D Open attached CSV, copy newdata and paste it to database CSV Outlook VBA and Custom Forms 2
makinmyway Research Pane in Emails Turns on and Cut Paste Keys then Stop Working Using Outlook 5
L Outlook 2007 Delete and Paste Between Fields Using Outlook 25
L "sometimes" cant send mail, we have to copy and paste the message and resend? Using Outlook 2
I Clipboard paste in macro Using Outlook 14
F Cut and Paste Addresses from Excel Suddenly Limited Using Outlook 4
N Cut and Paste Taking 25 seconds Using Outlook 0
R how to copy a list of email contacts and paste them only as names (not names + email address) Using Outlook 12
G Outlook 2007 Macro: Paste - Paste Special - Unformatted Text Outlook VBA and Custom Forms 9
K How to copy Contact Item to Clipboard and Paste as "VCF Link? Outlook VBA and Custom Forms 4
Z unable to paste screenshot into custom form Outlook VBA and Custom Forms 2
S Using copy paste to grab email addresses from the TO: address fiel Using Outlook 14
E PgUp and PgDn don't work for displayed message content (but do for web pages) Using Outlook 4
H Search Email Header for Content Type Outlook VBA and Custom Forms 1
icacream content in this message could not be downloaded.... Using Outlook 2
semnaitik Is it possible to recover content from a 0KB PST file? Using Outlook 3
Ms_Cynic Auto-pasting email content in calendar appt? Using Outlook 2
GregS What controls content of Folder Pane? Using Outlook 1
J Outlook 2016 message content does not display - outlook.com; exchange Using Outlook.com accounts in Outlook 9
J Assess content of User Defined Field in Rule Using Outlook 3
K ind specific Subject line from outlook and copy the content of the email body to exce Outlook VBA and Custom Forms 0
M Problems Downloading Content from Server(s) Using Outlook 0
N Rename Subject Line with Email Content Outlook VBA and Custom Forms 3
J Contacts 2016 Web page address content lost after updates Using Outlook 2
Randy Redekopp Outlook 2016 attachment content search Outlook VBA and Custom Forms 2
M How to duplicate content of one field in another field? Outlook VBA and Custom Forms 3
Z alter the timeout for how long outlook looks for a content-server on an HTML-email? Using Outlook 5
H Rule to move emails based on subject and content Outlook VBA and Custom Forms 1
R Can BCM monitor and select specific emails and use content info to update the client's record? BCM (Business Contact Manager) 1

Similar threads

Back
Top