PC Review
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
VBA Outlook, attachments question
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
VBA Outlook, attachments question
![]() |
VBA Outlook, attachments question |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Please help, I have 2 questions.
1/. I want my routine to send all .doc files in a folder to a contact but how, the Attachments.Add will not allow me to put "c:\docsemail\*.doc 2/. I want to start Outlook before running this sub routine because it is part of a loop, it will be very slow if I open Outlook for every email. I tried to move the fist 2 lines to the main routine but the sub routine would then fail at the "Set olMail = olApp.CreateItem (olMailItem" line. Sub EmailDoc() Dim olApp As Outlook.Application Set olApp = New Outlook.Application Dim olMail As MailItem Set olMail = olApp.CreateItem(olMailItem) With olMail .To = "Smith, John" .Subject = "New documents" .Attachments.Add "c:\docsemail\test.txt" .Attachments.Add "c:\docsemail\test2.txt" .Send End With Set olMail = Nothing olApp.Quit Set olApp = Nothing End Sub |
|
|
|
#2 |
|
Guest
Posts: n/a
|
You have to loop and add only 1 attachment at a time to the
Attachments collection. Declare your Outlook object at the module level so it is global to your code and then instantiate it before you call your processing procedure. Dim olApp As Outlook.Application Sub Something() Set olApp = CreateObject("Outlook.Application") Call EmailDoc Set olApp = Nothing End Sub Sub EmailDoc() 'whatever End Sub -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Lead Author, Professional Outlook 2000 Programming, Wrox Press Lead Author, Beginning VB 6 Application Development, Wrox Press Attachment Options http://www.slovaktech.com/attachmentoptions.htm Extended Reminders http://www.slovaktech.com/extendedreminders.htm "newboy18" <newboy18@msn.com> wrote in message news:041701c33fc7$b0a41150$a001280a@phx.gbl... > Please help, I have 2 questions. > 1/. I want my routine to send all .doc files in a folder > to a contact but how, the Attachments.Add will not allow > me to put "c:\docsemail\*.doc > 2/. I want to start Outlook before running this sub > routine because it is part of a loop, it will be very slow > if I open Outlook for every email. I tried to move the > fist 2 lines to the main routine but the sub routine would > then fail at the "Set olMail = olApp.CreateItem > (olMailItem" line. > > Sub EmailDoc() > Dim olApp As Outlook.Application > Set olApp = New Outlook.Application > Dim olMail As MailItem > Set olMail = olApp.CreateItem(olMailItem) > With olMail > .To = "Smith, John" > .Subject = "New documents" > .Attachments.Add "c:\docsemail\test.txt" > .Attachments.Add "c:\docsemail\test2.txt" > .Send > End With > Set olMail = Nothing > olApp.Quit > Set olApp = Nothing > End Sub |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Thanks Ken,
It works fine now, I did a Do until loop for just the Attachment and followed your advise for the rest >-----Original Message----- >You have to loop and add only 1 attachment at a time to the >Attachments collection. > >Declare your Outlook object at the module level so it is global to >your code and then instantiate it before you call your processing >procedure. > >Dim olApp As Outlook.Application > >Sub Something() > Set olApp = CreateObject("Outlook.Application") > Call EmailDoc > Set olApp = Nothing >End Sub > >Sub EmailDoc() > 'whatever >End Sub > > >-- >Ken Slovak >[MVP - Outlook] >http://www.slovaktech.com >Lead Author, Professional Outlook 2000 Programming, Wrox Press >Lead Author, Beginning VB 6 Application Development, Wrox Press >Attachment Options >http://www.slovaktech.com/attachmentoptions.htm >Extended Reminders >http://www.slovaktech.com/extendedreminders.htm > > >"newboy18" <newboy18@msn.com> wrote in message >news:041701c33fc7$b0a41150$a001280a@phx.gbl... >> Please help, I have 2 questions. >> 1/. I want my routine to send all .doc files in a folder >> to a contact but how, the Attachments.Add will not allow >> me to put "c:\docsemail\*.doc >> 2/. I want to start Outlook before running this sub >> routine because it is part of a loop, it will be very slow >> if I open Outlook for every email. I tried to move the >> fist 2 lines to the main routine but the sub routine would >> then fail at the "Set olMail = olApp.CreateItem >> (olMailItem" line. >> >> Sub EmailDoc() >> Dim olApp As Outlook.Application >> Set olApp = New Outlook.Application >> Dim olMail As MailItem >> Set olMail = olApp.CreateItem(olMailItem) >> With olMail >> .To = "Smith, John" >> .Subject = "New documents" >> .Attachments.Add "c:\docsemail\test.txt" >> .Attachments.Add "c:\docsemail\test2.txt" >> .Send >> End With >> Set olMail = Nothing >> olApp.Quit >> Set olApp = Nothing >> End Sub > > >. > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

