Consulting

Results 1 to 7 of 7

Thread: Solved: Problem in Application.OnKey Method

  1. #1
    VBAX Tutor Erdin? E. Ka's Avatar
    Joined
    Sep 2006
    Location
    Bursa
    Posts
    264
    Location

    Solved: Problem in Application.OnKey Method

    Hi,

    I want to if activecell is not empty then activecell / 1,18 to activecell.
    I can do it via directly runnig the codes below:

    [vba]Sub KDV()
    If ActiveCell.Value <> "" Then ActiveCell.Value = (ActiveCell.Value / 1.18)
    End Sub[/vba]

    But my problem is, when i try to run KDV macro via keaborad shortcut for CTRL and i doing noting.

    What should i do for assign KDV macro to a binary keyboard shortcut combination? For example, CTRL and F12 or CTRL and G... something like this...

    My ThisWorkbook codes as below:

    [vba]
    Sub Auto_Open()
    Application.OnKey "^i", "KDV" ' Ctrl & i combination
    End Sub
    [/vba]

    [vba]
    Sub Auto_Close()
    Application.OnKey "^i", ""
    End Sub
    [/vba]

    Thank you very much.
    Last edited by Erdin? E. Ka; 11-11-2006 at 04:54 PM. Reason: Missing attaching file
    Erdin? E. Kara?am | Loves from Bursa city in Republic of T?rkiye

  2. #2
    VBAX Tutor Erdin? E. Ka's Avatar
    Joined
    Sep 2006
    Location
    Bursa
    Posts
    264
    Location
    Now, i solved my problem. Thanks.
    Erdin? E. Kara?am | Loves from Bursa city in Republic of T?rkiye

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    How did you solve it?
    SamT

  4. #4
    VBAX Tutor Erdin? E. Ka's Avatar
    Joined
    Sep 2006
    Location
    Bursa
    Posts
    264
    Location
    I moved Auto_Open and Auto_Close procedures to Module1. Then i closed Excel application. And re opened the book. And i tried again to run. Finally it worked well.
    Erdin? E. Kara?am | Loves from Bursa city in Republic of T?rkiye

  5. #5
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Erdinc,

    For reference, Auto_Open and Auto_Close are old syntaxs that have been hanging around a while. Common practice is to use Workbook_Open and Workbook_Close events that are located in the ThisWorkbook module.

    I don't believe that there is any ill effect by choosing either way, but just thought I'd mention it.

    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Ken Puls
    For reference, Auto_Open and Auto_Close are old syntaxs that have been hanging around a while. Common practice is to use Workbook_Open and Workbook_Close events that are located in the ThisWorkbook module.

    I don't believe that there is any ill effect by choosing either way, but just thought I'd mention it.
    Yes there is.

    Auto_Open doesn't run if opened from within another piece of code or automation.

  7. #7
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Ah, well there you go. Thanks, Bob!

    I've never actually had the need to structure a solution to make use of that yet. Good to know.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





Posting Permissions

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