+ Reply to Thread
Results 1 to 4 of 4

Application.onkey error 1004 (even with very simple code)

Hybrid View

  1. #1
    Registered User
    Join Date
    09-29-2021
    Location
    Montreal, Canada
    MS-Off Ver
    365
    Posts
    2

    Application.onkey error 1004 (even with very simple code)

    Hello all! This is my first post, I just registered, hopefully I won't break any forum rules.

    I am trying to make application.Onkey work on my excel. I keep getting error 1004 message. I decided to try at least to make it work in a new .xlsm file with nothing in it, except this code... and I still get the error message. I really don't know what is wrong. Please help.

    Private Sub Workbook_Open()
    Application.OnKey "^{+}{P}", "test"
    End Sub

    Sub test()
    ThisWorkbook.Sheets(1).Range("a1").Select
    End Sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,353

    Re: Application.onkey error 1004 (even with very simple code)

    You might need to Select Sheets(1) before you can select a cell on it.

    Depends which sheet is Active when the workbook opens.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    09-29-2021
    Location
    Montreal, Canada
    MS-Off Ver
    365
    Posts
    2

    Re: Application.onkey error 1004 (even with very simple code)

    Hello, thanks for the answer. I tried to add a select and I still get the same error message.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,353

    Re: Application.onkey error 1004 (even with very simple code)

    Examples:

    Option Explicit
    
    Sub test()
    ' action
    Debug.Print "test"
    ThisWorkbook.Sheets(1).Range("a1").Select
    End Sub
    
    Sub test2()
    ' switch *on*
    ' Ctrl-Shift-P
    Debug.Print "test2"
    Application.OnKey "^{P}", "test"
    End Sub
    
    Sub test3()
    ' switch *off*
    ' Ctrl-Shift-P
    Debug.Print "test3"
    Application.OnKey "^{P}", ""
    End Sub
    These are all in a standard module for testing.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA - Getting application error code 1004 when trying to fetch defects from QC 10
    By Aki1403 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-06-2016, 03:37 AM
  2. HELP WITH ERROR CODE '1004' Application-defined or object defined error
    By QuintonMcCloud in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-20-2015, 03:34 PM
  3. [SOLVED] Error 1004 (application-defined) in my VBA code
    By sdehod in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-17-2013, 04:35 PM
  4. [SOLVED] Getting Error 1004 Object or Application Defined Error - Code to rearrange data
    By BlazzedTroll in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 06-10-2013, 12:10 PM
  5. Error When Implementing Code: "1004 - Application-defined or object-defined error"
    By blueblazingdemon in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-10-2013, 11:21 AM
  6. Application Error 1004 running Pivot Code
    By grifter in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-16-2012, 12:23 PM
  7. [SOLVED] Application-Defined or Object-Defined Error on simple code
    By brentfid@hotmail.com in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-22-2005, 05:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1