Solved

Can a keypress bypass a startup macro?

Posted on 2003-11-11
3
454 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Basic Excel Formatting error 4 81
VBA/SQL - Connect to SQL server and pull data 4 88
TT Auto Dashboard 13 79
Set email body to html using vbscript 6 22
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

932 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

9 Experts available now in Live!

Get 1:1 Help Now