Run macro in another file

mrmaso

New Member
Joined
Oct 10, 2017
Messages
16
Hi,
I would like to run macro in different file. It means I have opened file (master) where I start up the macro which will open another file and there I need to do some actions. Is it possible to write macro in first (master) file or it must be somehow writtten in second (opened) file?

Thank you for help
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Your macro to process data in freshly-opened file can be in either of them (master or newly-opemned one).

If you do in master file:
Code:
worksheets.open "C:\my_folder\slavefile.xlsx"
sheets(1).range("A1")="Ammended by Kaper macro"
activeworkbook.save false
activeworkbook.close
your slave.xlsx will be opened, something written in its A1 cell in first sheet, then saved and closed.

So all changes occur not in master but in a "child" workbook.
 
Upvote 0
This I understand. But it is possible somehow to write macro in master file which will done these changes?
 
Upvote 0
But this code IS in "Master" file and changes are in "Slave" ...
 
Upvote 0
You are right, but I need to write macro which will done more actions. So one macro will open the file and second will done other tasks. But I try your solution with Cell change but there is also mistake and I dont know what I am doing wrong. There is error message
run-time error ´13´:
Type mismatch

when to come the line:
Sheets(Hárok1).Range("A47") = "Ammended by Kaper macro" - sheets name is "Hárok1"

So sheet is going to open but then is mistake.

Thank you.
 
Upvote 0
Use sheet name as a string - to let VBA know it is a string - use doublequotes as for text string to be inserted in a cell.
Code:
[COLOR=#333333]Sheets("Hárok1").Range("A47") = "Ammended by Kaper macro"[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,215,315
Messages
6,124,213
Members
449,148
Latest member
sweetkt327

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