Invoking clicking a command button

sheku

New Member
Joined
Jul 9, 2008
Messages
3
I have 2 files (file1.xls and file2.xls). File1 has a Command Button that triggers a VB Macro in it. Clicking this button processes a certain set of data in this file and populates a set of fields. File2 reads the output in file1 after the click of the button. However, instead of manually clicking on the button and getting the results, I would like to simulate the clicking on the Command Button in file1 from file2. Can anybody help, please?

I tried to invoke by calling the worksheet.calculate function of file1 from file2. But seems like it is stepping over this line without doing anything.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
isntead of invoking a command button of one workbook from anoher workbook why not invoke the macros in the first book form anoher

in the second book use a code line something like this

Application.Run "Book1.xls!test"

here Book1.xlsis the first workbook IS OPNED.

IF IT IS NOT OPNED YOU HAVE TO USE THE PATH ALSO
 
Upvote 0
instead of manually clicking on the button and getting the results, I would like to simulate the clicking on the Command Button in file1 from file2.
One way to do this is:

First, for your command button code, delete the Private precedent statement in its event line.

Example if this is your CommandButton code

Private Sub CommandButton1_Click()
MsgBox "Hello"
End Sub

change it to

Sub CommandButton1_Click()
MsgBox "Hello"
End Sub



Now, if the command button resides in a workbook named File1.xls and the command button is named CommandButton1 and it is situated on a worksheet named "Sheet1" then this macro from File2.xls, or any other workbook that is open in the same instance of Excel where File1.xls is open, will execute the command button code.

Sub test()
Run Workbooks("File1.xls").Worksheets("Sheet1").CommandButton1_Click
End Sub
 
Upvote 0
Thanks, Venkat and Tom.

I tried both these solutions.

When I used Venkat's solution, it gives me an error message saying "macro abc cannot be found. When I tried running Tom's solution, I am getting an error message and I cant figure it out yet.
 
Upvote 0
When I tried running Tom's solution, I am getting an error message and I cant figure it out yet.
When I tried running Tom's solution it worked great without any problem based on the information you gave, then I (or was it he) posted it on the basis of that successful test.
 
Upvote 0
Tom has given expert soltuion and it should work.
reg my solution check whether the workbook name and the mcro name is ok. also check whether book1 is opened.
 
Upvote 0
Oh both of you guys' solutions were great and it worked when I tested it with 2 sample files. However, the current issue that I am working on has four files that are open. So, I dont know if this is causing the problem. I did read from Tom's solution that the two files that are open should be in the same instance. I am just a novice and do not know hwo to get around this and hence the follow-up questions.

The files I mentioned are used as below:

file1: Receives input, processes it and outputs the result in the same file
file2: Takes the data from file3 and feeds to file1; Also, extracts the output in file1 and writes it to file4
file3: Input file with rows of data
file4: Output extracted from file1

Regarding solution by Venkat: I checked the workbook name and the macro name and it is correct
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top