Variable Attachments in CDO/OL2K7?

Status
Not open for further replies.
C

corquando

Greetings, geniuses.

I have a standard CDO send sub that works just dandy, except for one

small detail.

For each email there will be a variable amount of attachments -

anywhere from 1 to maybe 15 tops.

In the .With statement, I have this (all required statements beforehand

are present. I'm just omitting them here for space's sake.):

Code:

------------------
'looped for each email sent

With iMsg

Set .Configuration = iConf

> To = EML 'email address from database

> CC = ""

> BCC = ""

> From = "Me@MyMailbox.com"

> Subject = Subj 'defined in the db

> TextBody = strbody 'defined in the db

> AddAttachment (Atch1) 'AHA!! Here's the rub!!

> Send

End With

[\code]

How may I:

a) Loop around the .AddAttachment statement to add the required attachments, or

b) define a variable that would contain the necessary attachment values (Atch1), and have the statement needed only once, and

c) which is best or does it matter?

I've seen solutions for non-CDO programs and earlier OL versions but I'm wary since what I'm doing is different, and spending 2 or 3 hours trying to force something that won't work anyway is demoralizing.

Please ask for whatever additional and needed items I have mindlessly omitted, and thanks in advance!!!

corquando
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Whereever you get the filenames of the attachments from, loop through it,

for instance with:

for i=1 to count

> ...

next

Best regards

Michael Bauer

Am Wed, 24 Feb 2010 22:05:12 +0000 schrieb corquando:


> Greetings, geniuses.

> I have a standard CDO send sub that works just dandy, except for one
> small detail.

> For each email there will be a variable amount of attachments -
> anywhere from 1 to maybe 15 tops.

> In the .With statement, I have this (all required statements beforehand
> are present. I'm just omitting them here for space's sake.):

> Code:
> ------------------
> 'looped for each email sent

> With iMsg
> Set .Configuration = iConf
> .To = EML 'email address from database
> .CC = ""
> .BCC = ""
> .From = "Me@MyMailbox.com"
> .Subject = Subj 'defined in the db
> .TextBody = strbody 'defined in the db
> .AddAttachment (Atch1) 'AHA!! Here's the rub!!
> .Send
> End With

> [\code]

> How may I:

> a) Loop around the .AddAttachment statement to add the required


attachments, or
> b) define a variable that would contain the necessary attachment values


(Atch1), and have the statement needed only once, and
> c) which is best or does it matter?

> I've seen solutions for non-CDO programs and earlier OL versions but I'm


wary since what I'm doing is different, and spending 2 or 3 hours trying to

force something that won't work anyway is demoralizing.

> Please ask for whatever additional and needed items I have mindlessly


omitted, and thanks in advance!!!
 
C

corquando

'Michael Bauer [MVP - Outlook Wrote:
> ;341979']Whereever you get the filenames of the attachments from, loop
> through it,
> for instance with:

> for i=1 to count
> ....
> next

> > Best regards
> Michael Bauer
>

>

> Herr Bauer:

> Vielen dank fur die Hilfe . . .

> And it accomplished the attaching quite well. The next issue, though,
> and it should be simple (I just don't know where to look) is to clear
> the Atch1 variable so I don't accumulate attachments on each successive
> send:
>
> >


Code:

--------------------
> >

> For i = 2 To z
> If Range("A" + CStr(i)) = "" Then GoTo 27
> Subj = Range("C" + CStr(i))
> EML = Range("E" + CStr(i))
> ID = Range("B" + CStr(i))
> Call TextBody(i, strbody)
> y = 0
> With iMsg
> Set .Configuration = iConf
> .To = EML
> .CC = ""
> .BCC = ""
> .From = "MyBox@MyAddress.com"
> .Subject = Subj
> .TextBody = strbody
> Do While Range("B" + CStr(i + y)) = ID
> DocName = Range("D" + CStr(i + y))
> Atch1 = "C:\Huge\Medium\Small\" + DocName + ".pdf"
> .AddAttachment (Atch1): y = y + 1
> Loop
> .Send
> End With
> 27 Next

> [\code]

> Each successive email has all the attachments that previous emails have had plus the new ones. I am sure it's an elementary command, but CDO statement catalogs are hard to come by.

> And I know it's simple - I'm good at simple.

> Noch einmal danke sehr.


corquando
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
The variable is cleared, or overwritten respectively, automatically as soon

as you write the next file name into it. However, atch1="" will also do it.

Best regards

Michael Bauer

Am Fri, 26 Feb 2010 21:39:48 +0000 schrieb corquando:


> 'Michael Bauer [MVP - Outlook Wrote:
> > ;341979']Whereever you get the filenames of the attachments from, loop
> > through it,
> > for instance with:
>

>> for i=1 to count
> > ....
> > next
>

>> > > Best regards
> > Michael Bauer
> >

> >
>

>
>> Herr Bauer:
>

>> Vielen dank fur die Hilfe . . .
>

>> And it accomplished the attaching quite well. The next issue, though,
> > and it should be simple (I just don't know where to look) is to clear
> > the Atch1 variable so I don't accumulate attachments on each successive
> > send:
> >
> >>

> Code:
> --------------------
> > >

> > For i = 2 To z
> > If Range("A" + CStr(i)) = "" Then GoTo 27
> > Subj = Range("C" + CStr(i))
> > EML = Range("E" + CStr(i))
> > ID = Range("B" + CStr(i))
> > Call TextBody(i, strbody)
> > y = 0
> > With iMsg
> > Set .Configuration = iConf
> > .To = EML
> > .CC = ""
> > .BCC = ""
> > .From = "MyBox@MyAddress.com"
> > .Subject = Subj
> > .TextBody = strbody
> > Do While Range("B" + CStr(i + y)) = ID
> > DocName = Range("D" + CStr(i + y))
> > Atch1 = "C:\Huge\Medium\Small\" + DocName + ".pdf"
> > .AddAttachment (Atch1): y = y + 1
> > Loop
> > .Send
> > End With
> > 27 Next
>

> > [\code]
>

> > Each successive email has all the attachments that previous emails


have had plus the new ones. I am sure it's an elementary command, but CDO

statement catalogs are hard to come by.
>

> > And I know it's simple - I'm good at simple.
>

> > Noch einmal danke sehr.
 
C

corquando

Alrighty, then . . .

I'd tried that, but it still 'stacked up' the attachments; then I

noticed that I had only one CDO session opened, and was looping through

the records within that one session. Evidently the session was

remembering the attachments and sending them as they piled up.

What I finally did (using the 'Atch="" ' command) was to loop through

the records, opening and then closing a CDO session for each email. It

still went just as fast, so evidently that's acceptable.

Thanks and best regards!

corquando
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A How to assign the value returned by the regex execute function to a variable? Using Outlook 1
J Automatic color category according to variable domains Outlook VBA and Custom Forms 4
J Object Variable or With Block Not Set Error in Outlook 2016 and not Outlook 2013 Outlook VBA and Custom Forms 3
R Macro to copy email to excel - Runtime Error 91 Object Variable Not Set Outlook VBA and Custom Forms 11
B InputBox for variable folder Outlook VBA and Custom Forms 7
D Outlook Rules - How to use a variable in the subject condition Outlook VBA and Custom Forms 9
M Modifying Macro MoveAgedMail(2) - use categories & "to" as variable Using Outlook 12
A Outlook VBA - moving mail item to public folder using variable within path Using Outlook 6
E Outlook could not create the work file. Check the temp environment variable Using Outlook 8
M VSTO C#: How do I declare an application scope variable? Outlook VBA and Custom Forms 2
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
G Schedule recurring email and attachments display Outlook VBA and Custom Forms 3
G Save and Rename Outlook Email Attachments Outlook VBA and Custom Forms 0
L Macro/VBA to Reply All, with the original attachments Outlook VBA and Custom Forms 3
A Attachments.Delete Outlook VBA and Custom Forms 3
M Deleting attachments does not reduce file size Using Outlook 0
L unblocking attachments before sending Office 365 Advanced Protection Using Outlook 0
I Saving attachments from multiple emails and updating file name Outlook VBA and Custom Forms 0
R Use an ItemAdd to Save Attachments on Arrival Outlook VBA and Custom Forms 0
shrydvd vba to secure zip attachments Outlook VBA and Custom Forms 3
R fetching blocked attachments Outlook VBA and Custom Forms 0
H Outlook 2016 sent over 30 copies of an e-mail with attachments Using Outlook 1
W Automatically open attachments without automatically printing them Using Outlook 0
O Save attachments using hotkey without changing attributes Outlook VBA and Custom Forms 1
T Outlook converts sent email to txt attachments when sync Using Outlook 0
Nadine Rule to move attachments with specific name Outlook VBA and Custom Forms 1
R Outlook is NOT removing attachments. Using Outlook 4
Dan_W Nested email attachments Outlook VBA and Custom Forms 4
M Print email and, attachments sent in hyperlinks in the email Outlook VBA and Custom Forms 2
W Save and rename outlook email attachments to include domain name & date received Outlook VBA and Custom Forms 4
S DRAGGING MAIL AND ATTACHMENTS TO CALENDAR Using Outlook 1
D Print attachments automatically and moves the mail to a new folder Outlook VBA and Custom Forms 9
G Download pdf attachments only if email subject has one of words Outlook VBA and Custom Forms 8
D Saving Selected Emails as PDF and saving Attachments Outlook VBA and Custom Forms 6
R Quick Access view in File Explorer when saving attachments Using Outlook 0
J Save E-mail attachments in a specific folder Outlook VBA and Custom Forms 0
O Wishlist Native solution to detach attachments but keep a link to them Outlook Wishlist 1
broadbander Needing help with reply/reply all while keeping attachments and adding a new CC recipient. Outlook VBA and Custom Forms 5
I Forwarding attachments in email received Outlook VBA and Custom Forms 3
A Outlook - Send New 20 Attachments through Email Using Outlook 4
D Print Attachments only in selected emails using a macro Outlook VBA and Custom Forms 3
M Outlook 2016 msg attachments Using Outlook 0
N Saving And Deleting Outlook Attachments with Unknown Error Message Outlook VBA and Custom Forms 1
M Macro for attachments download adjustment Outlook VBA and Custom Forms 3
M VBA macro for Inbox's attachments search Outlook VBA and Custom Forms 0
C Auto save outlook attachments when email is received Outlook VBA and Custom Forms 1
S Outlook 2010 Cannot Open Attachments Using Outlook 14
I Print Automatically Attachments Outlook VBA and Custom Forms 3
Diane Poremsky Save Messages and Attachments to a New Folder Using Outlook 0
B Delete/replace old files and save new attachments Using Outlook 1

Similar threads

Top