|
-
Mar 25th, 2010, 01:55 AM
#1
Thread Starter
Lively Member
Fire macros from a single macro....
Hey guys ,
i have 4 macros that copy paste data from another workbook.
I want to have one macro that fires the other 3. Note that each macro is placed into a different sheet, in the same workbook. Is this possible?
How can we call the other 3 macros if they are in a different sheet?
Thanks
-
Mar 25th, 2010, 02:17 AM
#2
Re: Fire macros from a single macro....
the macros need to be public procedure, at least not private
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 25th, 2010, 04:43 PM
#3
Thread Starter
Lively Member
Re: Fire macros from a single macro....
 Originally Posted by westconn1
the macros need to be public procedure, at least not private
what if the macros aree in different workbooks in the same folder.
can't we do it?
-
Mar 26th, 2010, 02:25 AM
#4
Re: Fire macros from a single macro....
yes you can do
vb Code:
Set s = Workbooks("book1.xls").Sheets("sheet1") Application.Run s.mymacro ' or for macros in a module application.run "book1.xls!mymacro"
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 28th, 2010, 05:26 PM
#5
Thread Starter
Lively Member
Re: Fire macros from a single macro....
 Originally Posted by westconn1
yes you can do
vb Code:
Set s = Workbooks("book1.xls").Sheets("sheet1")
Application.Run s.mymacro
' or for macros in a module
application.run "book1.xls!mymacro"
i tried to put the code to my main workbook to fire the other macros my i get an error.
Subscript out of range..
Set s = Workbooks("All brand Projects.xls").Sheets("sheet1")
Application.Run s.mymacro
' or for macros in a module
application.run "All brand Projects.xls!mymacro"
don't we need to open the other workbooks before we fire the macros?
i placed that code to a module on my main spreadsheet(master data). and i need to link it with the other workbooks so i can run the macros...
i tried it but am getting errors
-
Mar 29th, 2010, 02:55 AM
#6
Re: Fire macros from a single macro....
i did assume they would be open already
vb Code:
Set s = Workbooks.Open("book1.xls").Sheets("mysheet") Application.Run s.mymacro
if you want a workbook object set that first on open, then set the sheet
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 29th, 2010, 04:31 PM
#7
Thread Starter
Lively Member
Re: Fire macros from a single macro....
 Originally Posted by westconn1
i did assume they would be open already
vb Code:
Set s = Workbooks.Open("book1.xls").Sheets("mysheet")
Application.Run s.mymacro
if you want a workbook object set that first on open, then set the sheet
Set s = Workbooks.Open("\\NASFILE02\prou\My O Files\Desktop\status 2\FINA\fiNAL\Publish on\Express.xls").Sheets(" Express Report")
Application.Run s.Sample4thats my macro.
am getting this error.
object doesn't support this property or method.
any idea on what am doing wrong?
-
Mar 30th, 2010, 04:20 AM
#8
Re: Fire macros from a single macro....
can't see from here, the code should work ok, i have tested on a couple of workbooks, you sure the macro name is correct and on the correct sheet
which line do you get error?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 30th, 2010, 08:36 PM
#9
Thread Starter
Lively Member
Re: Fire macros from a single macro....
QUOTE=westconn1;3765403]can't see from here, the code should work ok, i have tested on a couple of workbooks, you sure the macro name is correct and on the correct sheet
which line do you get error?[/QUOTE]
am getting error in this line................
Application.Run s.Sample4
after s. i just put the name of my macro that is included in a module.....
is there any way we can run a macro without opening the workbooks?
updating the workbooks without opening them?
-
Mar 31st, 2010, 05:05 AM
#10
Re: Fire macros from a single macro....
is there any way we can run a macro without opening the workbooks?
updating the workbooks without opening them?
no, you have to open each make changes and close & save, no need to be visible to the user
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
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
|