|
-
Jul 27th, 2004, 05:00 AM
#1
Thread Starter
New Member
How to simulate a command button click in another workbook (resolved)
Harlow,
I have 2 workbooks and I want to simulate a click on one of the buttons in workbook A via some vba code in workbook B. How can I do that?
Thanks in advance....
Last edited by shaolang; Aug 2nd, 2004 at 02:39 AM.
-
Jul 27th, 2004, 10:09 AM
#2
Fanatic Member
workbook1.modulname.Button_onClick at a guess.
-
Jul 27th, 2004, 08:45 PM
#3
Thread Starter
New Member
That can't work, b'cos the buttons are drawn on a worksheet, not a userform. I can't modify the visibility of the button1_click() subroutine to public, which is kinda huge restrain.
-
Jul 28th, 2004, 09:27 PM
#4
You need to use the Shapes collection for buttons.
HTH
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 
-
Jul 29th, 2004, 01:47 AM
#5
Thread Starter
New Member
But how exactly do you do that? I could get hold of the command button via the Shapes collection, but how do I make the shape "click"? Calling
Code:
worksheets(1).Shapes("commandbutton1").click
gives me a "method not found error".
-
Aug 2nd, 2004, 02:38 AM
#6
Thread Starter
New Member
How to simulate a command button click in another workbook (resolved)
After a few days of searching, I've finally found the answer to the problem, and thought it might be useful to share in the forum.
There isn't a convenient way to simulate a click on a button that resides in a different worksheet where the code is (the only way is to use the Win32api), but since clicking the button is the same as pressing spacebar on the an activated button, I could just use the SendKeys() function. The code might look like this:
Code:
' code in worksheet B
dim obj as OLEObject ' will reference to a button in workbook A
set obj = Workbooks("A").ActiveSheet.Shapes(1).OLEFormat.Object
obj.Activate ' must activate the button so SendKeys() will send the spacebar to the intended button
SendKeys " " ' sends a spacebar, to simulate a click
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
|