Solved

Can a keypress bypass a startup macro?

Posted on 2003-11-11
3
462 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

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 86

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

717 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