ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Ignore MsgBox if run by automation (https://www.excelbanter.com/excel-programming/272380-re-ignore-msgbox-if-run-automation.html)

Dan E[_2_]

Ignore MsgBox if run by automation
 
My suggestion would be to make a function that takes an argument and does
everything you want it to ie:
Private Function MyFunction(Send as Boolean)
code . . .
If Send = True then
code to send . . .
End If
code . . .
End Function

Then for your button
Private Sub myButton_Click()
If MsgBox("Do you want to send this report?", vbYesNo) = vbYes Then
MyFunction Send:=TRUE
Else
MyFunction Send:=FALSE
End If
End Sub

For your other code
MyFunction Send:=TRUE

Dan E

"Tod" wrote in message
...
I have something like this:

If MsgBox("Do you want to send this report?", vbYesNo) =
vbYes Then
'Code to send report
End If

When the code is being executed from a button on the
worksheet, it will give the user the choice. However, I
also have a script that opens this workbook each morning
and runs the same procedure. Is there a way I can have the
procedure know it's being run by a script and accept the
default (which I think is Yes)?

tod





All times are GMT +1. The time now is 06:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com