Solved

Can a keypress bypass a startup macro?

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

770 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