Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Problem with setting object using session ID (emailing ffrom VBA)

Hi all,

I found a tremendous chunk of code (see below) at :
http://www.outlookcode.com/codedetail.aspx?id=1333

It works a treat except for one thing, it creates the email but does not
send it (I am using Outlook 2007); it puts it in the drafts folder and you
then have to send it manually. I have had a go at debugging it and it seems
that the line:

Set itm = Application.Session.GetItemFromID(ID)

(near the end) is failing as when I break before the next line (itm.Send)
itm is empty (i.e. the code returned nothing).

Does anyone have any idea how I can fix this so the email just sends
automatically rather than being placed in the drafts folder and/or how to
fix the line that isn't working if they are not one and the same problem
(which I suspect they are).

Thanks and regards, Mark

__________________________________________________ ___________________

Sub SendDocAsMsg()
Dim wd As Word.Application
Dim doc As Word.Document
Dim itm As Object
Dim ID As String
Dim blnWeOpenedWord As Boolean
Dim sSubject As String
Dim sEmailAddress As String


On Error Resume Next

sSubject = "Follow up"
sEmailAddress = "

Set wd = GetObject(, "Word.Application")
If wd Is Nothing Then
Set wd = CreateObject("Word.Application")
blnWeOpenedWord = True
End If
Set doc = wd.Documents.Open(Filename:="C:\WRWRInfo1.docx",
ReadOnly:=True)
Set itm = doc.MailEnvelope.Item

With itm
.from = sEmailAddress
.To = sEmailAddress
.CC = sEmailAddress
.Subject = sSubject
.Save
ID = .EntryID
End With

Set itm = Nothing

Set itm = Application.Session.GetItemFromID(ID)
itm.Send
doc.Close wdDoNotSaveChanges
If blnWeOpenedWord Then
wd.Quit
End If

Set doc = Nothing
Set itm = Nothing
Set wd = Nothing
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,805
Default Problem with setting object using session ID (emailing ffrom VBA)

I could not compile it with Word 2007 and got the error "Method or data
member not found" pointing to Session...

But why are you even doing that? Simply replace .Save by .Send like in the
code below
With itm
.from = sEmailAddress
.To = sEmailAddress
.CC = sEmailAddress
.Subject = sSubject
.Save
ID = .EntryID
End With

and comment out the lines
'Set itm = Application.Session.GetItemFromID(ID)
'itm.Send



"Mark Stephens" wrote:



Hi all,

I found a tremendous chunk of code (see below) at :
http://www.outlookcode.com/codedetail.aspx?id=1333

It works a treat except for one thing, it creates the email but does not
send it (I am using Outlook 2007); it puts it in the drafts folder and you
then have to send it manually. I have had a go at debugging it and it seems
that the line:

Set itm = Application.Session.GetItemFromID(ID)

(near the end) is failing as when I break before the next line (itm.Send)
itm is empty (i.e. the code returned nothing).

Does anyone have any idea how I can fix this so the email just sends
automatically rather than being placed in the drafts folder and/or how to
fix the line that isn't working if they are not one and the same problem
(which I suspect they are).

Thanks and regards, Mark

__________________________________________________ ___________________

Sub SendDocAsMsg()
Dim wd As Word.Application
Dim doc As Word.Document
Dim itm As Object
Dim ID As String
Dim blnWeOpenedWord As Boolean
Dim sSubject As String
Dim sEmailAddress As String


On Error Resume Next

sSubject = "Follow up"
sEmailAddress = "

Set wd = GetObject(, "Word.Application")
If wd Is Nothing Then
Set wd = CreateObject("Word.Application")
blnWeOpenedWord = True
End If
Set doc = wd.Documents.Open(Filename:="C:\WRWRInfo1.docx",
ReadOnly:=True)
Set itm = doc.MailEnvelope.Item

With itm
.from = sEmailAddress
.To = sEmailAddress
.CC = sEmailAddress
.Subject = sSubject
.Save
ID = .EntryID
End With

Set itm = Nothing

Set itm = Application.Session.GetItemFromID(ID)
itm.Send
doc.Close wdDoNotSaveChanges
If blnWeOpenedWord Then
wd.Quit
End If

Set doc = Nothing
Set itm = Nothing
Set wd = Nothing
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel (Session) Hijacking problem Bob[_4_] Excel Discussion (Misc queries) 0 April 12th 07 04:46 PM
Startup and template locations in Citrix TS session and local session John Nurick Setting up and Configuration of Excel 2 September 21st 06 10:42 PM
setting up a mailing list for bulk emailing with handimail OUTLOOK PROBLEMM Excel Discussion (Misc queries) 0 February 22nd 06 09:39 AM
Start a new session when a session is already opend MD Excel Programming 1 December 17th 05 05:47 PM
NetDDE problem - from a non-interactive session Diego Zeballos Fraigne Excel Programming 0 March 2nd 04 11:41 PM


All times are GMT +1. The time now is 10:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"