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!
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
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
P Can't paste an image into a task Using Outlook 1
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 8
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 New Slipstick.com Articles 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
S I'm not able to copy and paste on outlook. Using Outlook 1
M Outlook 2007 Copy-Paste problems Using Outlook 6
L Hyperlins within Outlook will not work, I have to cut and paste to internet explorer, how can this be fixed Using Outlook 1
F I cannot highlight text in Microsoft Outlook 2010 e-mails, and copy/paste to the body of another e-m Using Outlook 3
J cannot copy and paste while in list view in-cell editing Using Outlook 1
N Cannot paste image in the body of an email, it will only attach it as a file. Using Outlook 4
A UNABLE TO PASTE WEBSITE DATA INTO A NEW EMAIL Using Outlook 3
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
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

Similar threads

Top