|
-
Apr 20th, 2005, 11:17 PM
#1
Thread Starter
Addicted Member
Application.OnKey prblm in Excel 2003
I have this small piece of vba code in ThisWorkbook object:
Private Sub Workbook_Open()
Application.OnKey "%{z}", "OptionListBox"
End Sub
Private Sub OptionListBox()
Userform1.Show
End Sub
What it does is the user can press Ctrl-z at any moment to launch a form from my workbook. Easy enough.
Everything is kosher except that, if I save the workbook (WB1) under a new name (WB2), then press ctrl-z, it loads the previous file(WB1) and runs the code from there. In other word, the call is being make from that old file.Grrr..
Ive tried to incorporate some With ActiveWorkbook in some key places in the code, but no success whatsoever.
I don't know how to attach this to a specific file, can't I run two instances for seperate workbooks on my screen?
Can anyone help me plz?
Thanx
-
Apr 21st, 2005, 12:04 AM
#2
Re: Application.OnKey prblm in Excel 2003
Ok, I have dealt with something similar in Word before so its practically the same thing.
What you need to be doing is when you do your saveas you need to copy over the ThisWorkbook class code to
the new workbook, since the saveas doesnt copy the vba code modules/classes.
Or you could add your code to the xlt template so its centralized and all your saveas workbooks will reference this template.
Is this a local app or are you supporting other users?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 21st, 2005, 12:24 AM
#3
Thread Starter
Addicted Member
Re: Application.OnKey prblm in Excel 2003
Hi there Rob!
I know that when I save the workbook under another name, all the code is being included as well. So say I have Data2004.xls with bunch of code in it, if I save it under Data2005.xls, I will now have 2 files with the same code in it.
Now keep in mind that I'm still fairly a beginner with coding, so perhaps I'm not grasping what you're saying.
My problem is that the onkey event seems to be only launching from the 1st workbook. But I think I just solved it. I will post my result and the code if it works.
But If you could give me a quick insight on how to post my code, on this board, in the vbe format like you guys do, that'd be great. You click Code or VBCode?
Tx
-
Apr 22nd, 2005, 12:03 AM
#4
Thread Starter
Addicted Member
Re: Application.OnKey prblm in Excel 2003
For future reference here's what I've done:
VB Code:
Code in ThisWorkbook:
===========================
Private Sub Workbook_Activate()
TrapKey
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnKey "%{z}"
End Sub
Code in Module:
===========================
Sub TrapKey()
If ActiveWorkbook Is ThisWorkbook Then _
Application.OnKey "%{z}", "LoadMyForm"
End Sub
Last edited by D-niss; Apr 25th, 2005 at 05:10 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|