Add Multiple Attachments Sources using VBA in Word

Status
Not open for further replies.
J

JBark

Hi,

How can this code be written to add multiple attachments using vba and Word

as my email editor. The first attachment is the active document itself, the

other 4 attachments have their full path names stored in a field in the

document. This is what I have but I'm getting a syntax error and I'm not sure

why. Any suggestions are greatly appreciated.

> Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _

> Add Source:=ActiveDocument.TextBox("TextBoxFile1").Result,

Type:=olByValue, _

> Add Source:=ActiveDocument.TextBox("TextBoxFile2").Result,

Type:=olByValue, _

> Add Source:=ActiveDocument.TextBox("TextBoxFile3").Result,

Type:=olByValue, _

> Add Source:=ActiveDocument.TextBox("TextBoxFile4").Result,

Type:=olByValue

> Send
 
S

Sue Mosher [MVP]

You need a separate .Attachments.Add statement for each attachment, not one

long statement with multiple calls to the .Add method.

Sue Mosher

"JBark" <JBark> wrote in message

news:B6DFBA55-0410-444F-8A4B-1FE91DAD0B3C@microsoft.com...
> Hi,

> How can this code be written to add multiple attachments using vba and
> Word
> as my email editor. The first attachment is the active document itself,
> the
> other 4 attachments have their full path names stored in a field in the
> document. This is what I have but I'm getting a syntax error and I'm not
> sure
> why. Any suggestions are greatly appreciated.

> .Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
> .Add Source:=ActiveDocument.TextBox("TextBoxFile1").Result,
> Type:=olByValue, _
> .Add Source:=ActiveDocument.TextBox("TextBoxFile2").Result,
> Type:=olByValue, _
> .Add Source:=ActiveDocument.TextBox("TextBoxFile3").Result,
> Type:=olByValue, _
> .Add Source:=ActiveDocument.TextBox("TextBoxFile4").Result,
> Type:=olByValue
> .Send
>
 
J

JBark

Yes - I had tried that also like this, but I'm still getting syntax error.

> Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _

> Attachments.Add Source:=ActiveDocument.TextBox("TextBoxFile1").Result,

Type:=olByValue, _

> Attachments.Add Source:=ActiveDocument.TextBox("TextBoxFile2").Result,

Type:=olByValue, _

> Attachments.Add Source:=ActiveDocument.TextBox("TextBoxFile3").Result,

Type:=olByValue, _

> Attachments.Add Source:=ActiveDocument.TextBox("TextBoxFile4").Result,

Type:=olByValue

> Send

"Sue Mosher [MVP]" wrote:


> You need a separate .Attachments.Add statement for each attachment, not one
> long statement with multiple calls to the .Add method.
> > Sue Mosher
> > >

> "JBark" <JBark> wrote in message
> news:B6DFBA55-0410-444F-8A4B-1FE91DAD0B3C@microsoft.com...
> > Hi,
> > How can this code be written to add multiple attachments using vba and
> > Word
> > as my email editor. The first attachment is the active document itself,
> > the
> > other 4 attachments have their full path names stored in a field in the
> > document. This is what I have but I'm getting a syntax error and I'm not
> > sure
> > why. Any suggestions are greatly appreciated.
> > .Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
> > .Add Source:=ActiveDocument.TextBox("TextBoxFile1").Result,
> > Type:=olByValue, _
> > .Add Source:=ActiveDocument.TextBox("TextBoxFile2").Result,
> > Type:=olByValue, _
> > .Add Source:=ActiveDocument.TextBox("TextBoxFile3").Result,
> > Type:=olByValue, _
> > .Add Source:=ActiveDocument.TextBox("TextBoxFile4").Result,
> > Type:=olByValue
> > .Send
> >


>
 
S

Sue Mosher [MVP]

This is still all one statement, because of the underscore continuation

characters at the end of the first four lines.

Sue Mosher

"JBark" <JBark> wrote in message

news:E7B89599-FD4F-4E32-9052-569B27FBB3CB@microsoft.com...
> Yes - I had tried that also like this, but I'm still getting syntax error.

> .Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
> .Attachments.Add Source:=ActiveDocument.TextBox("TextBoxFile1").Result,
> Type:=olByValue, _
> .Attachments.Add Source:=ActiveDocument.TextBox("TextBoxFile2").Result,
> Type:=olByValue, _
> .Attachments.Add Source:=ActiveDocument.TextBox("TextBoxFile3").Result,
> Type:=olByValue, _
> .Attachments.Add Source:=ActiveDocument.TextBox("TextBoxFile4").Result,
> Type:=olByValue
> .Send

> "Sue Mosher [MVP]" wrote:
>
> > You need a separate .Attachments.Add statement for each attachment, not
> > one
> > long statement with multiple calls to the .Add method.
>

>> "JBark" <JBark> wrote in message
> > news:B6DFBA55-0410-444F-8A4B-1FE91DAD0B3C@microsoft.com...
> > > Hi,
> >> > How can this code be written to add multiple attachments using vba and
> > > Word
> > > as my email editor. The first attachment is the active document itself,
> > > the
> > > other 4 attachments have their full path names stored in a field in the
> > > document. This is what I have but I'm getting a syntax error and I'm
> > > not
> > > sure
> > > why. Any suggestions are greatly appreciated.
> >>> > .Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
> > > .Add Source:=ActiveDocument.TextBox("TextBoxFile1").Result,
> > > Type:=olByValue, _
> > > .Add Source:=ActiveDocument.TextBox("TextBoxFile2").Result,
> > > Type:=olByValue, _
> > > .Add Source:=ActiveDocument.TextBox("TextBoxFile3").Result,
> > > Type:=olByValue, _
> > > .Add Source:=ActiveDocument.TextBox("TextBoxFile4").Result,
> > > Type:=olByValue
> > > .Send
> > >

>

>
>>
 
J

JBark

Thanks Sue. The code runs fine without any errors and attaches the original

doc but not the additional docs. Should I ask someone over in the Word Forum

about this? Or do you have a suggestion as to why the additional files will

not attach?
 
S

Sue Mosher [MVP]

If you have already made the change I suggested -- removing the extraneous

underscore characters so that you have each Attachments.Add call in a

separate statement -- I would suggest looking at the actual value of what

you're getting from the ActiveDocument.TextBox("TextBoxFile1").Result

expressions.

Sue Mosher

"JBark" <JBark> wrote in message

news:F602CE82-F4CD-4545-8F73-AC8A8BCC8A77@microsoft.com...
> Thanks Sue. The code runs fine without any errors and attaches the
> original
> doc but not the additional docs. Should I ask someone over in the Word
> Forum
> about this? Or do you have a suggestion as to why the additional files
> will
> not attach?


"Sue Mosher [MVP]" <suemvp@turtleflock.com> wrote in message

news:Obl0OZN%23JHA.2824@TK2MSFTNGP03.phx.gbl...
> This is still all one statement, because of the underscore continuation
> characters at the end of the first four lines.

> "JBark" <JBark> wrote in message
> news:E7B89599-FD4F-4E32-9052-569B27FBB3CB@microsoft.com...
> > Yes - I had tried that also like this, but I'm still getting syntax
> > error.
>

>> .Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
> > .Attachments.Add
> > Source:=ActiveDocument.TextBox("TextBoxFile1").Result,
> > Type:=olByValue, _
> > .Attachments.Add
> > Source:=ActiveDocument.TextBox("TextBoxFile2").Result,
> > Type:=olByValue, _
> > .Attachments.Add
> > Source:=ActiveDocument.TextBox("TextBoxFile3").Result,
> > Type:=olByValue, _
> > .Attachments.Add
> > Source:=ActiveDocument.TextBox("TextBoxFile4").Result,
> > Type:=olByValue
> > .Send
>

>> "Sue Mosher [MVP]" wrote:
> >
> >> You need a separate .Attachments.Add statement for each attachment, not
> >> one
> >> long statement with multiple calls to the .Add method.
> >
>>> "JBark" <JBark> wrote in message
> >> news:B6DFBA55-0410-444F-8A4B-1FE91DAD0B3C@microsoft.com...
> >> > Hi,
> >>>> > How can this code be written to add multiple attachments using vba and
> >> > Word
> >> > as my email editor. The first attachment is the active document
> >> > itself,
> >> > the
> >> > other 4 attachments have their full path names stored in a field in
> >> > the
> >> > document. This is what I have but I'm getting a syntax error and I'm
> >> > not
> >> > sure
> >> > why. Any suggestions are greatly appreciated.
> >>>>>> > .Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue,
> >> > _
> >> > .Add Source:=ActiveDocument.TextBox("TextBoxFile1").Result,
> >> > Type:=olByValue, _
> >> > .Add Source:=ActiveDocument.TextBox("TextBoxFile2").Result,
> >> > Type:=olByValue, _
> >> > .Add Source:=ActiveDocument.TextBox("TextBoxFile3").Result,
> >> > Type:=olByValue, _
> >> > .Add Source:=ActiveDocument.TextBox("TextBoxFile4").Result,
> >> > Type:=olByValue
> >> > .Send
 
J

JBark

Yes - I kept digging and I was declaring the fields as formfields but they're

really textboxes. It works now like this:

> .Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue

> Attachments.Add Source:=ActiveDocument.TextBoxFile1.Value,

Type:=olByValue

> Attachments.Add Source:=ActiveDocument.TextBoxFile2.Value,

Type:=olByValue

> Attachments.Add Source:=ActiveDocument.TextBoxFile3.Value,

Type:=olByValue

> Attachments.Add Source:=ActiveDocument.TextBoxFile4.Value,

Type:=olByValue

> Send

Thanks a bunch for your help!

"Sue Mosher [MVP]" wrote:


> If you have already made the change I suggested -- removing the extraneous
> underscore characters so that you have each Attachments.Add call in a
> separate statement -- I would suggest looking at the actual value of what
> you're getting from the ActiveDocument.TextBox("TextBoxFile1").Result
> expressions.
> > Sue Mosher
> > >

> "JBark" <JBark> wrote in message
> news:F602CE82-F4CD-4545-8F73-AC8A8BCC8A77@microsoft.com...
> > Thanks Sue. The code runs fine without any errors and attaches the
> > original
> > doc but not the additional docs. Should I ask someone over in the Word
> > Forum
> > about this? Or do you have a suggestion as to why the additional files
> > will
> > not attach?


> "Sue Mosher [MVP]" <suemvp@turtleflock.com> wrote in message
> news:Obl0OZN%23JHA.2824@TK2MSFTNGP03.phx.gbl...
> > This is still all one statement, because of the underscore continuation
> > characters at the end of the first four lines.
> > "JBark" <JBark> wrote in message
> > news:E7B89599-FD4F-4E32-9052-569B27FBB3CB@microsoft.com...
> >> Yes - I had tried that also like this, but I'm still getting syntax
> >> error.
> >
> >> .Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
> >> .Attachments.Add
> >> Source:=ActiveDocument.TextBox("TextBoxFile1").Result,
> >> Type:=olByValue, _
> >> .Attachments.Add
> >> Source:=ActiveDocument.TextBox("TextBoxFile2").Result,
> >> Type:=olByValue, _
> >> .Attachments.Add
> >> Source:=ActiveDocument.TextBox("TextBoxFile3").Result,
> >> Type:=olByValue, _
> >> .Attachments.Add
> >> Source:=ActiveDocument.TextBox("TextBoxFile4").Result,
> >> Type:=olByValue
> >> .Send
> >
> >> "Sue Mosher [MVP]" wrote:
> >
> >>> You need a separate .Attachments.Add statement for each attachment, not
> >>> one
> >>> long statement with multiple calls to the .Add method.
> >>
> >>> "JBark" <JBark> wrote in message
> >>> news:B6DFBA55-0410-444F-8A4B-1FE91DAD0B3C@microsoft.com...
> >>> > Hi,
> >>> >>> > How can this code be written to add multiple attachments using vba and
> >>> > Word
> >>> > as my email editor. The first attachment is the active document
> >>> > itself,
> >>> > the
> >>> > other 4 attachments have their full path names stored in a field in
> >>> > the
> >>> > document. This is what I have but I'm getting a syntax error and I'm
> >>> > not
> >>> > sure
> >>> > why. Any suggestions are greatly appreciated.
> >>> >>> >>> > .Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue,
> >>> > _
> >>> > .Add Source:=ActiveDocument.TextBox("TextBoxFile1").Result,
> >>> > Type:=olByValue, _
> >>> > .Add Source:=ActiveDocument.TextBox("TextBoxFile2").Result,
> >>> > Type:=olByValue, _
> >>> > .Add Source:=ActiveDocument.TextBox("TextBoxFile3").Result,
> >>> > Type:=olByValue, _
> >>> > .Add Source:=ActiveDocument.TextBox("TextBoxFile4").Result,
> >>> > Type:=olByValue
> >>> > .Send


>
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
O Outlook tasks - Add text column with multiple lines Using Outlook 3
A Add multiple servers "on behalf of" email to "safe senders" list. Using Outlook 1
C Macro to add multiple recipients to message Outlook VBA and Custom Forms 3
Z bulk add categories / with fixed colours / select multiple categories on a not Using Outlook 1
S how to add multiple namespace in one AD, exchange 2010 Exchange Server Administration 3
S How to add multiple exchange accounts without password / credential prompt? Using Outlook 5
M How to add multiple contacts directly from To List of an email Using Outlook 4
R Add multiple individuals as meeting organizer Using Outlook 4
K 2003 Outlook Contacts - how do I add text to multiple contacts .... Outlook VBA and Custom Forms 2
J OL add-In for multiple versions Outlook VBA and Custom Forms 1
U Not able to delete Add-in button from multiple Outlook Explorer Outlook VBA and Custom Forms 1
G Add to Outlook Contacts - Point to non-default contacts folder Using Outlook 0
M Automatically add senders first name to a greeting Outlook VBA and Custom Forms 1
C Add Form to Appointments Received, Automatically Outlook VBA and Custom Forms 6
W April 2020 Office 365 Update - Add-Ons fail after Office 365 Update Using Outlook 6
B Task Filter Not Working When I add too many criteria Using Outlook 0
D Add date next to day name in Outlook Today calendar view Using Outlook 1
D iCloud Add-in not working in Outlook 2013 and Outlook 2016 After Windows Upgrade & iCloud Upgrade Using Outlook 2
P Add Paste Unformatted to QAT Using Outlook 1
M Ignore slow add-ins Using Outlook 0
B Add Prefix text to Subject Line Using Outlook 1
Jennifer Murphy Add birthdays to calendar Using Outlook 7
Z Add text to auto-forwarded e-mail Outlook VBA and Custom Forms 4
P Add, remove, & reorder folder pane Using Outlook 6
L Tired of Outlook disabling Adobe PDF Creator add-in Using Outlook 1
R Add 'Company' to Select Names Form Using Outlook 1
A Outlook 2016 Web add-in missing on some machines Using Outlook 9
P Syncing problems with add-ins Using Outlook 3
Mark Foley Cannot enable add-in in outlook 2010 Using Outlook 0
BretAB Is it possible to add a lookup field to a Message form? Outlook VBA and Custom Forms 4
J Add an Attachment Using an Array and Match first 17 Letters to Matching Template .oft to Send eMail Outlook VBA and Custom Forms 2
iwshim outlook 2013 - I cannot see the "Manage Add-ins" Using Outlook 2
S Add Exchange Account as Secondary to Existing PST? Exchange Server Administration 1
A Add to Outlook Contacts from email - default view Outlook VBA and Custom Forms 1
P Add a contact to the New Task in Outlook 2016 Using Outlook 2
e_a_g_l_e_p_i Is there a way to add something that is in the "Format Text" tab to the "basic Text" on the message tab Using Outlook 1
B When working on emails in a certain folder, when I hit reply or reply all, I would like it re always reply all and add an email address to send to Outlook VBA and Custom Forms 3
M Macro to add date/time stamp to subject Outlook VBA and Custom Forms 4
O Outlook on Android - add BCC Using Outlook 2
J Execute Add-In Button from VBA Outlook 2016 Outlook VBA and Custom Forms 1
S Example VBA Macro - To Conditionally Change the From Account and Add a BCC Address on Emails Outlook VBA and Custom Forms 11
B When I add more search strings to RULES, it is not processing them Using Outlook 3
D Add Tetxbox at form open Outlook VBA and Custom Forms 1
Andrew Quirl Open attachment, manipulate without add-on program? Outlook VBA and Custom Forms 5
B Searching for a Add-In Using Outlook 3
J Add Fillable Fields to Existing Template Outlook VBA and Custom Forms 1
J vb to c# for Outlook add-in. Using Outlook 0
S Send email via SMTP - use transport rules to add to senders inbox (then rule to move to sent items Exchange Server Administration 1
R Outlook add-in to create new contact from an email. Using Outlook 0
twofivepie GTD Netcentrics add-in for 2016 Outlook VBA and Custom Forms 13
Similar threads


















































Top