Solved

Can a keypress bypass a startup macro?

Posted on 2003-11-11
3
450 Views
Last Modified: 2008-03-17
I have a VBA login function for Outlook 2002 that runs on Application startup (soon to be a COM addin). I'd like a way to bypass it, e.g holding the shift key when starting outlook will mean the macro isn't called (analogous to AllowBypassKey in Access). Is there some code or workaround to do that? Thanks!

                                         
0
Comment
Question by:adampirg
  • 2
3 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9728093
I don't know about making the macro not be called from Outlook, but you could certainly check in VB to see if the shift key is down on load, and then immediately exit.  Like this...

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Const VK_SHIFT = &H10

Private Sub Form_Load()
    If GetAsyncKeyState(VK_SHIFT) <> 0 Then
        Unload Me
    End If
End Sub

Don't know if you can apply this to your login function.  Hope it helps.

Idle_Mind
0
 

Author Comment

by:adampirg
ID: 9732789
Idle_Mind-- Can you be a little more specific about where to put this code? Some of it is unfamiliar to me (e.g. the first line) . For example, since the Application_Startup event in ThisOutlookSession loads the form, I put the first 2 lines (the declarations) in ThisOutlookSession, and then I could modify the rest like this:

Private Sub Application_Startup()
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 9733409
I've never done quite what you are doing but I imagine it would be done like this:

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Const VK_SHIFT = &H10

Private Sub Application_Startup()
    If GetAsyncKeyState(VK_SHIFT) <> 0 Then
        Unload Me
    Else
        ' Logon code here
    End If
End Sub
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now