Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 26 of 26

Thread: Outlook 2010 - macro "Print 1st page" - Problem with Num Lock turning off

  1. #21
    Would that work?
    ty it and see

  2. #22
    VBAX Regular
    Joined
    Jan 2014
    Posts
    14
    Location
    Not sure I know how all the 0,0,1 bits work though

  3. #23
    each key has to be pushed down, then released
    like
    keybd_event 50, 1, 0, 0 
    keybd_event 50, 1, KEYEVENTF_KEYUP, 0 
    where 50 is i believe the P key

  4. #24
    Quote Originally Posted by westconn1 View Post
    each key has to be pushed down, then released
    like
    keybd_event 50, 1, 0, 0 
    keybd_event 50, 1, KEYEVENTF_KEYUP, 0 
    where 50 is i believe the P key
    Hi,

    I have an identical problem. Was using SendKeys until people reported their Numlock turning off. Have been reading this thread and have tried to use Num_Off and Num_On before and after the sendkeys, but Num_On doesn't work. It seems to be ignored and the numlock ends up off when the print job has run.

    Did you have any luck with mapping each key stroke to a "keybd_event"?

  5. #25
    VBAX Regular
    Joined
    Jan 2014
    Posts
    14
    Location
    I must admit that due to other work commitments - I never had the chance to sit down and try and work through this. I am moving on from my job tomorrow so I may not get the opportunity to find out!

    Big thanks to Westconn1 though for all his/her help!

  6. #26
    Hi,

    No probs. Thanks for the reply anyway. I did some further digging around and finally worked out the combination needed. It took a while as a lot of the resources on the net refer to c++ and not VBA.

    This is my code, which I put in a new module on it's own.

    Private Declare Sub keybd_event Lib "user32" ( _ByVal bVk As Byte, _
    ByVal bScan As Byte, _
    ByVal dwFlags As Long, _
    ByVal dwExtraInfo As Long)
    Private Const VK_NUMLOCK = &H90
    Private Const KEYEVENTF_KEYUP = &H2
    Private Const VK_ALT = &H12
    Private Const VK_TAB = &H9
    Declare Function GetKeyState Lib "user32.dll" ( _
    ByVal nVirtKey As Long) As Integer
    
    
    Sub Print1()
     keybd_event VK_ALT, 0, 0, 0 'Key press ALT
     keybd_event 70, 1, 0, 0 'Key press F
     keybd_event 70, 1, KEYEVENTF_KEYUP, 0 'Key release F
     keybd_event VK_ALT, 0, KEYEVENTF_KEYUP, 0 'Key release ALT
     keybd_event 80, 1, 0, 0 'Key press P
     keybd_event 80, 1, KEYEVENTF_KEYUP, 0 'Key release P
     keybd_event 82, 1, 0, 0 'Key press R
     keybd_event 82, 1, KEYEVENTF_KEYUP, 0 'Key release R
     keybd_event VK_ALT, 0, 0, 0 'Key press ALT
     keybd_event 83, 1, 0, 0 'Key press S
     keybd_event 83, 1, KEYEVENTF_KEYUP, 0 'Key release S
     keybd_event VK_ALT, 0, KEYEVENTF_KEYUP, 0 'Key release ALT
     keybd_event 49, 1, 0, 0 'Key press 1
     keybd_event 49, 1, KEYEVENTF_KEYUP, 0 'Key release 1
     keybd_event 13, 1, 0, 0 'Key press ENTER
     keybd_event 13, 1, KEYEVENTF_KEYUP, 0 'Key release ENTER
    End Sub
    Here is a helpful article which shows the key mapping [scroll down a bit] http://www.experts-exchange.com/Prog..._24088649.html

    This works for me and my numlock stays on throughout!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •