Send keys in VBA on appearance of dialog box - vba

Back in this question, I was looking for a way of disabling a particularly troublesome dialog from Outlook that warned me the attachments I was sending might be unsafe. Having concluded that the only security-setting options were unavailable because of administrator privileges, I've instead been trying to look for a workaround to have a script active within Outlook that does something like the following (pseudo VBA):
sub PollForDialog()
if dialogbox = open and dialogbox.name = "This outgoing message may..." then
Sendkeys arrowleft + enter
I've tried exhaustively to search for how to have scripts execute upon a messagebox popping up, and I haven't had any luck. Plenty of stuff about dialog boxes opening when a script is run, but nothing I can find on how to trigger on a dialog opening. Anyone able to help?
Thanks muchly.

Related

How to manage application options/advanced options?

I need to quickly toggle File > Options > Advanced > Reminders > Play reminder sound setting.
In certain meetings I need to keep Outlook running to get reminders, but don't want the reminder sound.
Currently, I manually toggle the File > Options > Advanced > Reminders > Play reminder sound checkmark.
This needs to be an effective single-click.
I don't want to restart Outlook as there are usually many things open.
I cannot add it to the Quick Access Toolbar.
On the left the option is present in the list of QAT commands, but not in the list of Ribbon commands, otherwise we could access it with ExecuteMso.
Three reasons:
The button is disabled when not in the Calendar window. That's just inelegant.
When I click the button, Outlook crashes and I lose everything that wasn't saved. (Autosave isn't sufficient or functioning. That's a different problem.)
Understanding how to access Outlook settings with VBA opens a whole new world of possibilities.
This Microsoft article series starting at https://learn.microsoft.com/en-us/office/vba/outlook/concepts/getting-started/automating-outlook-from-a-visual-basic-application is about automating Outlook user tasks, like making a calendar appointment. That's not what I want, I want to manage Outlook's options.
There are some discussions about COM add-ins as one method, but that appears beyond me. The effort to learn COM add-ins is out of line with manual effort to achieve the desired goal.
I have some limited Outlook VBA experience but am reasonably comfortable with VBA in Word, Excel.
To disable reminder sound you need to set the below registry key to 0.
Registry key: PlaySound (REG_DWORD) to be set to 0.
Path: HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\options\Reminder
where 16.0 indicates the Outlook version.
Don't forget to restart Outlook to apply changes.
These settings can be overridden on the per appointment basis - you can simply set AppointmentItem.ReminderPlaySound property to false using VBA.
Simulate a button press with ExecuteMso.
https://learn.microsoft.com/en-us/office/vba/api/Office.CommandBars.ExecuteMso
Hover over the button where you would add it to the ribbon/QAT. See text in brackets at the end.
Are the command codes for ExecuteMso documented?
Private Sub ExecuteMso_TextInBrackets()
' https://learn.microsoft.com/en-us/office/vba/api/Office.CommandBars.ExecuteMso
' https://stackoverflow.com/questions/25610998/are-the-command-codes-for-executemso-documented
Dim oAppt As Object
Set oAppt = ActiveInspector.CurrentItem
Debug.Print oAppt.subject
ActiveInspector.CommandBars.ExecuteMso ("TextInBrackets")
End Sub
As with most things in life, the answer is a workaround. In this case, it's AutoHotkey to press the keys for me (ALT F, T, down x 9, ALT P, Enter):
;WIN-O toggles the Outlook alarm sound setting
#o::
SetTitleMatchMode,2 ;inexact match
WinGetActiveTitle, MyWindowTitle
If WinActive(" - email#company.com") ;Poor way to "prove" we're in Outlook
{
;MsgBox, We're in Outlook
Send !ft{Down 9}
Send !p{Enter}
}
Return

Hotkey to run macro when viewing the email

I have a macro that sends a reply to email selected in the inbox. I assigned it to the Quick Access Toolbar and run it by pressing alt+1.
The hotkey does not work when I view the email itself (I sometimes open it from within a task). In email view I can go to the macros ribbon and run it manually and it works, but I can't find the way to run it with the hotkey. Any suggestions?
I need to view email and decide if I run the reply macro or not, so a solution to run it on open action won't work.
edit: solution i comments
There is a separate Quick Access Toolbar for open mailitems. If the 1 is over the Save icon, you are currently saving with Alt+1.
If the code can process ActiveInspector.CurrentItem then you can add the macro.

Bring the security message box to the front when using Outlook VBA to send an email

I'm writing code to automate sending an email from Excel. Whenever the send function of Outlook is executed, there is a warning/security message box to approve before the email is sent.
The message box is beneath the other forms so the user has to find this message box to proceed with the other tasks.
Is there a way to have this message box appear on top?
The warning message is there for a reason.
However, you can bypass it, but you have to code the functions in C++ and call them from VBA or use a commercial lib that has already done this.
One i've used is: Redemption, website
I've been able to solve the "messagebox on top" issue by using the following:
Set outlookProgram = CreateObject("Outlook.Application")
outlookProgram.ActiveExplorer.Activate
Thanks for all you help guys.
P

How to force user to deal with the Security Warning when starting Access 2007?

When a user start an Access 2007 database that have macros and vba, a security warning is shown. I want the user to deal with this warning, so if the the content is't enabled, the user should not be able to use the database.
Now I use a macro named AutoExec (opens a form that works like a menu), and that macro is run before the user deal with the security warning. But I want to check if the content is enabled and if not I will show a form that inform the user that they should enable the content.
So what I'm actually asking for is how do I do this:
If vba and macros is not enabled -> show form "information"
If vba and macros is enabled -> show form "start menu"
Ok, after a while I have the solution. Thanks for the answers who led me the right way.
This article from Microsoft is very helpful.
In the AutoExec-macro, I have two lines:
Line one: Conditions: [CurrentProject].[IsTrusted]=False and then I choose witch Form I want to open and in this case it is the "info about security warning form"
Line two: Conditions: [CurrentProject].[IsTrusted]=True and now open the "start menu form"
And that's all!
If the content is disabled, then you cannot check, since your code cannot run....
You might like to consider a start-up form ("information"). This will show without macros.
In addition, you can run some start-up code or a macro that closes the information form and opens the main form ("start menu"), if macros are disallowed, this will not run. However, I think you may get an unsightly warning.
EDIT
Set the timer interval to say, 100 and add a little code to Information form:
Private Sub Form_Timer()
DoCmd.Close acForm, "Information"
DoCmd.OpenForm "start menu"
End Sub
Just to add my solution -- I was just dealing with this issue.
By default, in database options have it set to open with form "notEnabled"
On this "not enabled" form, have some text, pictures, or what have you that lets the user know that he/she needs to 'enable content'.
In the on load event for this form, just put some VBA to open the actual form you want the user to be presented and close the "notEnabled" form.
This way, if the user opens the database without making it trusted, enabling content, they are stuck on the form that tells them how to do that. As SOON as it's trusted, the on-load event of the form will fire and redirect the user to whichever form you want, with content enabled.
If the user opens the database and already has trusted the file, they don't see the form telling them to make it trusted.
You can avoid this by setting the IsTrusted flag to TRUE in your AutoExec macro. See Transitioning Your Existing Access Applications to Access 2007 -- search for IsTrusted to get you to the heart of the explanation of how to handle it.
I don't know why people give suggestions that have not been tested yet. My solution is simple:
If: [CurrentProject].[IsTrusted]=False
RunMenuCommand: CloseDatabase
Else
If: [CurrentProject].[IsTrusted]=True
RunCode: (you run the code or macro you wanted to in the first place here)
This basically closes the database if the security warnings are coming on. If they are not, it opens just fine. The user that is the admin will need to decrease the macro security levels on the computer of whoever wants to access the database. This macro unlike others will actually run because it agrees with what Access wants.
You're Welcome!

How to capture response from Cancel or Ok Button in two different Applications?

With my Application (vb.net) I am trying to scan Excel files some of which have ActiveX Components.
When running my Application, I am getting a pup-up window in Windows Vista Environment with Office-2007 having button OK and Cancel button to proceed.
But my problem is the scanning is not proceeding even after I keep on pressing the OK button. Now I want to continue with my application while pressing the Cancel button; i.e. just to skip the file. Is it possible to capture the response from the cancel button? (As this is a message box from another application, i.e. either from Vista or Office-2007, I'm not sure).
My main motive is to just ignore the message box to proceed....
Can anyone please help me out there....
Thank you....
The DisplayAlerts property of Microsoft.Interop.Excel.Application may help here.
If set to FALSE then Excel automatically chooses the default option on pop-up boxes.
Whether or not this applies to ActiveX controls I don't know but it may be worth trying.