Outlook object not being created

M

muyBN

When I ran the following code the first couple of times it created the
object, but now it won't. My objective is to create an e-mail with variables
defined previously in macro, and not sending it right away. Any suggestions?
(The reference library Outlook item is check-boxed in the menu.)

Dim objOutlookApp As Outlook.Application, objItem As Outlook.MailItem

With objItem
.To = strEmail
.Subject = strCo & ", " & " " & strJ
.Body = "message"
.Display
End With
Selection.InsertFile FileName:=strNew, Range:="", ConfirmConversions:=False,
Link:=False, Attachment:=True
Set objItem = Nothing
Set objOutlookApp = Nothing
 
J

Jezebel

Your code doesn't appear to create anything at all. You've declared the
objects, but you also need to instantiate them --

set objOutlookApp = Outlook.Application

etc
 
M

muyBN

Sorry, I left that part out of the post. Here's the complete code:

Dim objOutlookApp As Outlook.Application, objItem As Outlook.MailItem
....
Set objOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set objOutlookApp = CreateObject("Outlook.Application")
blnStarted = True
End If
Set objItem = objOutlookApp.CreateItem(olMailItem)
'select account to send from
Set OLI = M.GetInspector
If Not OLI Is Nothing Then
Set CBs = OLI.CommandBars
Set CBP = CBs.FindControl(, ID_ACCOUNTS)
If Not CBP Is Nothing Then
For Each MC In CBP.Controls
intLoc = InStr(MC.Caption, " ")
If intLoc > 0 Then
strAccountBtnName = Mid(MC.Caption, intLoc + 1)
Else
strAccountBtnName = MC.Caption
End If
If strAccountBtnName = AccountName Then
MC.Execute
Set_Account = AccountName
GoTo Exit_Function
End If
Next
End If
End If
Set_Account = ""

Exit_Function:
Set MC = Nothing
Set CBP = Nothing
Set CBs = Nothing
Set OLI = Nothing
....
 
M

muyBN

Can anyone help me with this?

--
Bryan


muyBN said:
Sorry, I left that part out of the post. Here's the complete code:

Dim objOutlookApp As Outlook.Application, objItem As Outlook.MailItem
...
Set objOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set objOutlookApp = CreateObject("Outlook.Application")
blnStarted = True
End If
Set objItem = objOutlookApp.CreateItem(olMailItem)
'select account to send from
Set OLI = M.GetInspector
If Not OLI Is Nothing Then
Set CBs = OLI.CommandBars
Set CBP = CBs.FindControl(, ID_ACCOUNTS)
If Not CBP Is Nothing Then
For Each MC In CBP.Controls
intLoc = InStr(MC.Caption, " ")
If intLoc > 0 Then
strAccountBtnName = Mid(MC.Caption, intLoc + 1)
Else
strAccountBtnName = MC.Caption
End If
If strAccountBtnName = AccountName Then
MC.Execute
Set_Account = AccountName
GoTo Exit_Function
End If
Next
End If
End If
Set_Account = ""

Exit_Function:
Set MC = Nothing
Set CBP = Nothing
Set CBs = Nothing
Set OLI = Nothing
...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top