Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Can a keypress bypass a startup macro?

Posted on 2003-11-11
3
Medium Priority
?
466 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
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…
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…
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…
Suggested Courses

610 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