Can I disable Outlook warning from Excel macro "Send" method

  • Thread starter Thread starter wpiet
  • Start date Start date
W

wpiet

I have an Excel macro that sends e-mails via Outlook, using the VBA "Send
Method."
For each message sent, Outlook displays a warning requiring a "Yes" response.
Is there a way, either in Outlook or in the Excel macro, to generate an
automatic reply to these messages?
 
Since that is using a Simple MAPI call none of the usual workarounds for
using Outlook automation will work for you such as Redemption
(www.dimastr.com/redemption). Try searching for "ClickYes" as a possible
workaround for you when using Simple MAPI calls that trigger the Outlook
object model guard.
 
Thanks for the suggestion, Ken. I'll be looking into that.
Is it possible to, alternatively, start from Outlook, access the Excel
workbook & process the VBA macro there which creates the e-mails & sends them?
I'm absolutely new at VB coding. I recorded the macro in Excel to set up the
data for the e-mails, then had to figure out a way to add the code to that
macro to create & send the e-mails using that data. Everything works
perfectly except for having to manually reply to the "Object Model Guard."

Thanks,
Will
 
If you're going to write the code in Outlook, why not just send the
emails from there? You'll have to recode the application, but it's a
lot better than having Outlook start Excel only to send emails using
Outlook.

HTH
 
If you are running the code from the Outlook VBA project and you use
Application there as your Outlook.Application object you will have a trusted
Application object. Then you derive all of your other Outlook objects from
that trusted Application object and those objects will be trusted. That will
eliminate the security warnings.

You can use the Outlook VBA code to open Excel and the workbook you want and
use code to extract the contents you want for the emails, all within your
Outlook VBA code. That's the way I'd be doing it.

The Excel VBA macro code can be moved over to Outlook, you will need to add
starter code to start Excel and open the workbook, and to fully qualify all
Excel references (Excel.Range instead of Range, etc.). Then the code for the
email can be done using Outlook automation code.

There should be examples of that sort of thing up on www.outlookcode.com,
try searching there for "Excel" and see what turns up.
 
My problem is that I don't have a clue what's possible from either
application, since I've never programmed for either one (or done any other
VBA coding).
As it is, the Excel workbook contains 5 worksheets & the macro does numerous
things, involving all of these sheets. The end result of the macro, before
the For Each . . . Next loop that accesses Outlook & sends the e-mails, is a
2-column worksheet, one column with e-mail addresses, the other with the
corresponding messages.
Are you saying that, from an Outlook macro, I can open the Excel workbook,
select that worksheet & loop through the rows, creating an e-mail for each
one?
Can I, in fact, do all the processing of the Excel workbook from the Outlook
macro, using CreateObject("Excel.Application") as the starting point, opening
the workbook & performing all the steps that are currently contained in the
Excel macro?
If so, I'm guessing it would mostly require changing the qualifiers on most
statements???

Thanks,
Will
 
Thanks, Ken. I didn't see your post before my response to JP. Yours answered
those questions of mine. Sounds like we're all on the same page, essentially.
I think I'm getting the idea. Thanks to both of you. You've been very helpful.

Will
 
Jimmy, did you just make a change to your site? I followed the link & was
reading the article but when I looked around the site and tried to go back to
the article, I got the "Something's wrong here" page.
I am able to access the main blog page, so I did a search on "export," got
six results but if I click on any of the result links, I get the same
"Something's wrong here" page. I noticed that the link you provided includes
"2008/08" in the URL but it redirects & drops the "2008." Thought that might
be relevant.
 
Ken & JP,

Thanks to both of you, everything works beautifully.

For the benefit of others looking for such a solution, here's the relevant
code from my Outlook macro that creates e-mails from an Excel workbook:

(sheet 'E-Mail' has 2 columns; 'A' = e-mail addresses; 'B' = text of
messages)

Sub MacroName()
Dim XL As Object
Dim WB As Workbook
Dim Cell As Range
Dim EmlMsg As MailItem

' Open Excel & workbook

Set XL = CreateObject("Excel.Application")
XL.Visible = True
Set WB = GetObject("\\Server\Folder\Master.xls")
XL.Windows("Master.xls").Visible = True

' Send e-mails

For Each Cell In XL.Sheets("E-Mail").Columns("B").Cells
If Cell.Value = "" Then
Exit For
Else
Set EmlMsg = CreateItem(0)

With EmlMsg
.To = Cell.Offset(0, -1)
.Subject = "Your Subject Here"
.Body = Cell.Value
.Send
End With

Set EmlMsg = Nothing
End If
Next Cell

' Release workbook & Excel application

Set WB = Nothing
Set XL = Nothing
End Sub
 
Nice job! You might also want to call the Quit Method on the Excel
Application Object, to make sure that instance of Excel is destroyed.
Just setting the reference to Nothing may not be enough.

HTH
 
Thanks for the Quit suggestion.
I also discovered an intermittent Error 9 (subscript out of range) on
'XL.Windows("Master.xls").Visible = True' because sometimes the preceding
statement,
'Set WB = GetObject("\\Server\Folder\Master.xls")' did not open the workbook.
I fixed that by replacing those two lines with:
XL.Workbooks.Open FileName:="\\Server\Folder\Master.xls",
which makes more sense, anyway. Live & learn!

Thanks, again.
--
Will


JP said:
Nice job! You might also want to call the Quit Method on the Excel
Application Object, to make sure that instance of Excel is destroyed.
Just setting the reference to Nothing may not be enough.

HTH
 
Hey, I'm always open to any suggestion. I have no idea what I'm doing! It's
all new to me, so any insight is appreciated. I had a few other issues rear
their ugly heads but seem to have worked them out. The last few times I've
run it through, it seems to be OK. Thanks for all your help.
 
Back
Top