Consulting

Results 1 to 5 of 5

Thread: paste without clipboard manager

  1. #1
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location

    paste without clipboard manager

    Hi everyone.

    I think I have a relatively easy question here: I want to be able to define a certain string to a hotkey (like ALT + V) in Windows so it will work in any application I'm in. The problem is, I can't install things at work (IT gets mad if I try)... so is there an easy way to make a generic macro to do this in Windows 2000?
    Office 2010, Windows 7
    goal: to learn the most efficient way

  2. #2
    VBAX Mentor Brandtrock's Avatar
    Joined
    Jun 2004
    Location
    Titonka, IA
    Posts
    399
    Location
    This is a routine that I yoinked from VBA Programmer which may be of some use in getting you pointed in the direction you want to go.

    Hope it helps.

    [vba]' API Constants & Declarations
    Public Const GWL_WNDPROC As Long = (-4)
    Public Const WM_HOTKEY As Long = &H312

    Public Const MOD_ALT = &H1
    Public Const MOD_CONTROL = &H2
    Public Const MOD_SHIFT = &H4

    Public Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" _
    (ByVal lpString As String) As Long

    Public Declare Function GlobalDeleteAtom Lib "kernel32" _
    (ByVal nAtom As Long) As Long

    Public Declare Function RegisterHotKey Lib "User32" _
    (ByVal hWND As Long, _
    ByVal id As Long, _
    ByVal fsModifiers As Long, _
    ByVal vk As Long) As Long

    Public Declare Function UnregisterHotKey Lib "User32" _
    (ByVal hWND As Long, _
    ByVal id As Long) As Long

    Public Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" _
    (ByVal hWND As Long, _
    ByVal nIndex As Long, _
    ByVal dwNewLong As Long) As Long

    Public Declare Function CallWindowProc Lib "User32" Alias "CallWindowProcA" _
    (ByVal lpPrevWndFunc As Long, _
    ByVal hWND As Long, _
    ByVal Msg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) As Long

    Public mlngLastWndProc As Long
    Public mlngAtom As Long

    ' Functions and Subroutines to store in main module
    ' Function which determines what happens when HotKey pressed
    Function WindowProc(ByVal hWND As Long, ByVal uMsg As Long, _
    ByVal wParam As Long, ByVal lParam As Long) As Long

    If hWND = Clipboard_Mgr_Frm.hWND And uMsg = WM_HOTKEY Then
    Clipboard_Mgr_Frm.Text1.Text = Clipboard_Mgr_Frm.Text1.Text & _
    Clipboard.GetText(vbCFText) & vbCrLf & vbCrLf
    End If

    WindowProc = CallWindowProc(mlngLastWndProc, hWND, uMsg, wParam, lParam)
    End Function

    ' Subroutine which creates the Hot Key
    Public Sub CreateHotKey(ByVal intKeyCode As Integer, ByVal hWND As Long)
    mlngAtom = GlobalAddAtom(CStr(Now))
    mlngLastWndProc = SetWindowLong(hWND, GWL_WNDPROC, AddressOf WindowProc)
    RegisterHotKey hWND, mlngAtom, 0, intKeyCode
    End Sub

    ' Subroutine which destroys the hot key
    Public Sub DestroyHotKey(ByVal hWND As Long)
    UnregisterHotKey hWND, GlobalDeleteAtom(mlngAtom)
    Call SetWindowLong(hWND, GWL_WNDPROC, mlngLastWndProc)
    End Sub

    ' Procedures in a particular form
    Private Sub Form_Load()
    CreateHotKey vbKeyF2, Me.hWND
    ' Message below to let user know hot key has been created and what it does.
    MsgBox "F2 is now a HOT KEY which will copy the clipboard contents" & vbCrLf & _
    "To the textbox (minimized) - from ANYWHERE on the system!" & vbCrLf & vbCrLf & _
    "REMEMBER to hit both Ctrl + C and F2 when copying text." & vbCrLf & vbCrLf & _
    "MAXIMIZE from the Taskbar to Insert text in Word document.", vbOKOnly, _
    " HOT KEY F2 PROCESS START"
    End Sub

    ' Remember to destroy hot key when exiting the form
    Private Sub cmdExit_Click()
    DestroyHotKey Me.hWND
    Unload Me
    End
    End Sub
    [/vba]
    Regards,
    Brandtrock




  3. #3
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Thanks Brandtrock, this looks promising.

    Am I going to get in trouble if I mess with API stuff at work? This, vba arrays and messing with registry items are things I'm afraid of. I know it's probably an irrational fear.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  4. #4
    VBAX Mentor Brandtrock's Avatar
    Joined
    Jun 2004
    Location
    Titonka, IA
    Posts
    399
    Location
    Care does need to be exercised when working with API calls and registry settings. Checking with the powers that be in the IT/IS department is probably a good idea, although they generally frown on anyone outside of their dominion doing anything more complex than strict alpha numeric data entry. Your relationship with the individuals in the department will be your guide as far as this is concerned.

    Having said that, don't be afraid of using these types of solutions. Just be sure of what you are doing ahead of time. Ivan Moala's site has a boat load of information on using API calls.

    Regards,
    Brandtrock




  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hi Tom and Brantrock,
    I don't wish to distract from your discussion but I use an excel workbook for pasting data to other apps. I use a worksheet change code that copies whats in the cell when I click on it then I can paste to any application from the clipboard. I know it's a little clunky but it works nicely and I use it often. Only caveat is you have to have the workbook open in the background. Not very elegant but it works.....

    [vba]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Selection.Copy
    End Sub[/vba]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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