Lucas Morin
Lucas Morin

Reputation: 398

Run a macro in a specified worksheet from another workbook

Here's my problem: I have two workbooks, one is mine, say Projet.xlsm, and the other is not, say Query.xlsm. Query.xlsm is shared between me and a lots of people in my company so I can't modify it.

My project.xlsm aims to plot some datas extracted with Query.xlsm. My job is to make it an automated process.

How Query.xlsm work: on the first sheet there is some options to select; then we have just to click a button on the first sheet. Finally all the datas are extracted and appears in second sheet.

I've built a macro in project.xlsm wich open Query.xlsm and select the options I want. Now I'm tryi,g to "click the button" (sheet1 in Query.xlsm) from my macro in my project.xlsm. I've tried things like this: running excel macro from another workbook But I think I have to mention the name of my sheet somewhere.

Thanks in advance

Upvotes: 0

Views: 4815

Answers (2)

Gaussian Blur
Gaussian Blur

Reputation: 638

Assuming you have the workbook open (which it sounds like you do), this worked for me even on a Private CommandButton Sub.

Workbooks("Query.xlsm").Sheets("Sheet1").CommandButton1 = True
Workbooks("Query.xlsm").Sheets("Sheet1").CommandButton1 = vbClick

Upvotes: 1

Santosh
Santosh

Reputation: 12353

You may create a public procedure in Query.xlsm Workbook in first sheet. cmdClick refers to the name of activex command button. Below is sample code.

Public Sub cmdClick()
    CommandButton1_Click
End Sub

You can call this procedure from project.xlsm using below syntax.

Workbooks("testing.xlsm").Sheets("Sheet1").cmdClick

Upvotes: 0

Related Questions