A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Sample Code for Merge With Attachments?



 
 
Thread Tools Search this Thread Display Modes
  #11  
Old August 18th 06, 03:05 PM posted to microsoft.public.outlook.program_vba
LongWayFromHome
external usenet poster
 
Posts: 7
Default Sample Code for Merge With Attachments?

OK. Adding the Word library reference cleared all the compile errors shown
above. Thank you!

Now I am getting new "Method or Data Member not found" compile errors. I
obviously made a mistake in attempting to follow your direction about
deriving Dialogs from a Word.Application object. Here are the lines I think
might be pertinent. The errors occur on all the .Methods:

Dim wdWordApp As Word.Application
Dim wdItem As Word.MailMessage
Set wdWordApp = GetObject(, "Word.Application")

Set wdItem = wdWordApp.MailMessage
With wdItem
' .Subject = mysubject
' .Body = ActiveDocument.Content
Set Datarange = Maillist.Tables(1).Cell(Counter, 1).Range
Datarange.End = Datarange.End - 1
' .To = Datarange
For i = 2 To Maillist.Tables(1).Columns.Count
Set Datarange = Maillist.Tables(1).Cell(Counter, i).Range
Datarange.End = Datarange.End - 1
' .Attachments.Add Trim(Datarange.Text), olByValue, 1
Next i
' .Send
End With

Sorry to be so lost on this.

Thanks.
--
Dave


"Sue Mosher [MVP-Outlook]" wrote:

Document and Range are Word classes. DId you add a reference to Word to your VBA project?

Dialogs is also a Word class, and you'll need to derive it from a Word.Application object, not Outlook.Application.


Ads
  #12  
Old August 18th 06, 03:09 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Sample Code for Merge With Attachments?

If Word is not running, GetObject(, "Word.Application") will return Nothing. You must test for that case and use CreateObject if necessary:

On Error Resume Next
Set wdWordApp = GetObject(, "Word.Application")
If wdWordApp Is Nothing Then
Set wdWordApp = CreateObject("Word.Application")
End If
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"LongWayFromHome" wrote in message ...
OK. Adding the Word library reference cleared all the compile errors shown
above. Thank you!

Now I am getting new "Method or Data Member not found" compile errors. I
obviously made a mistake in attempting to follow your direction about
deriving Dialogs from a Word.Application object. Here are the lines I think
might be pertinent. The errors occur on all the .Methods:

Dim wdWordApp As Word.Application
Dim wdItem As Word.MailMessage
Set wdWordApp = GetObject(, "Word.Application")

Set wdItem = wdWordApp.MailMessage
With wdItem
' .Subject = mysubject
' .Body = ActiveDocument.Content
Set Datarange = Maillist.Tables(1).Cell(Counter, 1).Range
Datarange.End = Datarange.End - 1
' .To = Datarange
For i = 2 To Maillist.Tables(1).Columns.Count
Set Datarange = Maillist.Tables(1).Cell(Counter, i).Range
Datarange.End = Datarange.End - 1
' .Attachments.Add Trim(Datarange.Text), olByValue, 1
Next i
' .Send
End With


  #13  
Old August 18th 06, 05:25 PM posted to microsoft.public.outlook.program_vba
LongWayFromHome
external usenet poster
 
Posts: 7
Default Sample Code for Merge With Attachments?

I have added your code, but Word has been open all along. GetObject returns
"Microsoft Word."
--
Dave


"Sue Mosher [MVP-Outlook]" wrote:

If Word is not running, GetObject(, "Word.Application") will return Nothing. You must test for that case and use CreateObject if necessary:

On Error Resume Next
Set wdWordApp = GetObject(, "Word.Application")
If wdWordApp Is Nothing Then
Set wdWordApp = CreateObject("Word.Application")
End If
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"LongWayFromHome" wrote in message ...
OK. Adding the Word library reference cleared all the compile errors shown
above. Thank you!

Now I am getting new "Method or Data Member not found" compile errors. I
obviously made a mistake in attempting to follow your direction about
deriving Dialogs from a Word.Application object. Here are the lines I think
might be pertinent. The errors occur on all the .Methods:

Dim wdWordApp As Word.Application
Dim wdItem As Word.MailMessage
Set wdWordApp = GetObject(, "Word.Application")

Set wdItem = wdWordApp.MailMessage
With wdItem
' .Subject = mysubject
' .Body = ActiveDocument.Content
Set Datarange = Maillist.Tables(1).Cell(Counter, 1).Range
Datarange.End = Datarange.End - 1
' .To = Datarange
For i = 2 To Maillist.Tables(1).Columns.Count
Set Datarange = Maillist.Tables(1).Cell(Counter, i).Range
Datarange.End = Datarange.End - 1
' .Attachments.Add Trim(Datarange.Text), olByValue, 1
Next i
' .Send
End With



  #14  
Old August 18th 06, 06:04 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Sample Code for Merge With Attachments?

Sorry, that was the obvious problem. I should have looked for others, like:

Set wdItem = wdWordApp.MailMessage

You need to use Outlook's Application.CreateItem method to create the message. And

ActiveDocument.Content

This and other calls to Word objects need to use wdWordApp as their parent:

wdWordApp.ActiveDocument.Content

These are good basics to know, BTW, so don't feel like you're wasting time learning them.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"LongWayFromHome" wrote in message ...
I have added your code, but Word has been open all along. GetObject returns
"Microsoft Word."
--
Dave


"Sue Mosher [MVP-Outlook]" wrote:

If Word is not running, GetObject(, "Word.Application") will return Nothing. You must test for that case and use CreateObject if necessary:

On Error Resume Next
Set wdWordApp = GetObject(, "Word.Application")
If wdWordApp Is Nothing Then
Set wdWordApp = CreateObject("Word.Application")
End If

"LongWayFromHome" wrote in message ...
OK. Adding the Word library reference cleared all the compile errors shown
above. Thank you!

Now I am getting new "Method or Data Member not found" compile errors. I
obviously made a mistake in attempting to follow your direction about
deriving Dialogs from a Word.Application object. Here are the lines I think
might be pertinent. The errors occur on all the .Methods:

Dim wdWordApp As Word.Application
Dim wdItem As Word.MailMessage
Set wdWordApp = GetObject(, "Word.Application")

Set wdItem = wdWordApp.MailMessage
With wdItem
' .Subject = mysubject
' .Body = ActiveDocument.Content
Set Datarange = Maillist.Tables(1).Cell(Counter, 1).Range
Datarange.End = Datarange.End - 1
' .To = Datarange
For i = 2 To Maillist.Tables(1).Columns.Count
Set Datarange = Maillist.Tables(1).Cell(Counter, i).Range
Datarange.End = Datarange.End - 1
' .Attachments.Add Trim(Datarange.Text), olByValue, 1
Next i
' .Send
End With



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
sample download Tomas Hak Add-ins for Outlook 0 July 19th 06 06:47 PM
Can I send attachments when doing an email merge? PVakerling Outlook - General Queries 1 June 29th 06 11:50 PM
transfer of zip code to word with mail merge doesn't work Ken Outlook - Using Contacts 1 April 25th 06 09:48 PM
VBA Code to put in Access that will send an Email with Attachments [email protected] Outlook and VBA 1 April 9th 06 06:30 PM
ICS attachments shows as HTML code and can't answer Zanvetto Outlook - Calandaring 0 February 16th 06 09:04 PM


All times are GMT +1. The time now is 09:16 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.