Sign in to follow this  
Followers 0
Wayne

Can I Use AutoIt MsgBox in Excel VBA?

6 posts in this topic

I've created an Excel VBA program using AutoIt that automates writing invoices in another application. Everything works good to this point but I want to add the AutoIt MsgBox to popup to supply some basic user information. I tried using Excel MsgBox but it forces the user to switch back to Excel just to read the message, then I have to switch them back to the application. From the tests I ran with AutoIt MsgBox in AU3 files, it remains with the active application, which is what I want. After setting up the AutoIt object in Excel as oAutiIt I tried the following two commands (neither worked):

oAutoIt.MsgBox (64, "Test", "Hello")

iResponse = oAutoIt.MsgBox (64, "Test", "Hello")

All other oAutoIt commands work great. What am I doing wrong? Can AutoIt MsgBox be used this way? Any help would be appreciated.

Wayne

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

AutoItX3 activex control doesn't have MsgBox method. If you're able to access the WScript object you can use it's MsgBox method.

Edit:

The MsgBox is exposes naturally to VBA applications.

Function MsgBox(Prompt, [Buttons As VbMsgBoxStyle = vbOKOnly], [Title], [HelpFile], [Context]) As VbMsgBoxResult
Const vbAbortRetryIgnore = 2
Const vbApplicationModal = 0
Const vbCritical = 16 (&H10)
Const vbDefaultButton1 = 0
Const vbDefaultButton2 = 256 (&H100)
Const vbDefaultButton3 = 512 (&H200)
Const vbDefaultButton4 = 768 (&H300)
Const vbExclamation = 48 (&H30)
Const vbInformation = 64 (&H40)
Const vbMsgBoxHelpButton = 16384 (&H4000)
Const vbMsgBoxRight = 524288 (&H80000)
Const vbMsgBoxRtlReading = 1048576 (&H100000)
Const vbMsgBoxSetForeground = 65536 (&H10000)
Const vbOKCancel = 1
Const vbOKOnly = 0
Const vbQuestion = 32 (&H20)
Const vbRetryCancel = 5
Const vbSystemModal = 4096 (&H1000)
Const vbYesNo = 4
Const vbYesNoCancel = 3
Edited by Authenticity

Share this post


Link to post
Share on other sites

I've created an Excel VBA program using AutoIt that automates writing invoices in another application. Everything works good to this point but I want to add the AutoIt MsgBox to popup to supply some basic user information. I tried using Excel MsgBox but it forces the user to switch back to Excel just to read the message, then I have to switch them back to the application. From the tests I ran with AutoIt MsgBox in AU3 files, it remains with the active application, which is what I want. After setting up the AutoIt object in Excel as oAutiIt I tried the following two commands (neither worked):

oAutoIt.MsgBox (64, "Test", "Hello")

iResponse = oAutoIt.MsgBox (64, "Test", "Hello")

All other oAutoIt commands work great. What am I doing wrong? Can AutoIt MsgBox be used this way? Any help would be appreciated.

Wayne

I've noticed this behavior before. Could a Win32 API call work instead?

Private Declare Function MessageBox _
    Lib "User32" Alias "MessageBoxA" _
       (ByVal hWnd As Long, _
        ByVal lpText As String, _
        ByVal lpCaption As String, _
        ByVal wType As Long) _
    As Long

...

MessageBox &H0, "Hello World", "Test", vbSystemModal

Taken from here: http://www.tek-tips.com/faqs.cfm?fid=4699

Share this post


Link to post
Share on other sites

I've noticed this behavior before. Could a Win32 API call work instead?

Private Declare Function MessageBox _
    Lib "User32" Alias "MessageBoxA" _
       (ByVal hWnd As Long, _
        ByVal lpText As String, _
        ByVal lpCaption As String, _
        ByVal wType As Long) _
    As Long

...

MessageBox &H0, "Hello World", "Test", vbSystemModal

Taken from here: http://www.tek-tips.com/faqs.cfm?fid=4699

Yes the Win32 API MsgBox works OK in Excel VBA but doesn't display on the application window I'm on. I have to minimize the app window or click on the MsgBox window tab to see the msgbox. Is there a way to bring the MsgBox forward so I can see it plus see my app window? As I said above I want to provide the user with information about the app window. Thanks.

Wayne

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Yes the Win32 API MsgBox works OK in Excel VBA but doesn't display on the application window I'm on. I have to minimize the app window or click on the MsgBox window tab to see the msgbox. Is there a way to bring the MsgBox forward so I can see it plus see my app window? As I said above I want to provide the user with information about the app window. Thanks.

Wayne

If you want to use the AutoIt MsgBox function, you might be able to call the AutoItX3.dll (in AutoItX subdirectory of AutoIt3 install). I don't know how to do that from VBA, but maybe smarter people do.

You could also code a regular AutoIt script that accepts command line inputs and compile that to an .exe that you call from Excel VBA.

Outside of that, this is not an AutoIt question.

:D

Edit: Oops. As Authenticity pointed out, MsgBox() is not included in AutoItX3.dll.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

If you want to use the AutoIt MsgBox function, you might be able to call the AutoItX3.dll (in AutoItX subdirectory of AutoIt3 install). I don't know how to do that from VBA, but maybe smarter people do.

You could also code a regular AutoIt script that accepts command line inputs and compile that to an .exe that you call from Excel VBA.

Outside of that, this is not an AutoIt question.

:D

I found a solution looking over the MsgBox Constants in VBA. Adding vbSystemModal to type, my MsgBox now appears above the application window exactly as I wanted. Thanks all for getting me on the right road. This code works great:

MessageBox &O0, "This is a native Message Box", "My Box", vbOKOnly + vbSystemModal

Wayne

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0