Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 51
Default write a macro to run a macro

Can a user write a mcaro that will automatically execute when the file is
opened?
--
Allan
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default write a macro to run a macro

hi
yes. use the workbook_open evert.
Private Sub Workbook_Open()
MsgBox "Hi"
End Sub

regards
FSt1

"Flipper" wrote:

Can a user write a mcaro that will automatically execute when the file is
opened?
--
Allan

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,722
Default write a macro to run a macro

Yes. From the VBE, under the ThisWorkbook module, you can use something like
this:

Private Sub Workbook_Open()
'Call a macro previously written
Application.Run "Book1!MyMacro"

'Any other coding you want to run
End Sub


Note that there are many other events you can use to automatically activate
macros.
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Flipper" wrote:

Can a user write a mcaro that will automatically execute when the file is
opened?
--
Allan

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 51
Default write a macro to run a macro

I don't understand. Where do this text string go in the event?
--
Allan


"FSt1" wrote:

hi
yes. use the workbook_open evert.
Private Sub Workbook_Open()
MsgBox "Hi"
End Sub

regards
FSt1

"Flipper" wrote:

Can a user write a mcaro that will automatically execute when the file is
opened?
--
Allan

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 51
Default write a macro to run a macro

Sorry, I am not understanding. Your verbiage "'Call a macro previously written
Application.Run "Book1!MyMacro"" waht does that mean? Do I insert the name of my Macro(s) here, or the name or my workbook? I presume that Book1!MyMacro would be the name of my macro? So does that mean Application.Run will execute it?

I'm very much a macro novice.
Thanks

--
Allan


"Luke M" wrote:

Yes. From the VBE, under the ThisWorkbook module, you can use something like
this:

Private Sub Workbook_Open()
'Call a macro previously written
Application.Run "Book1!MyMacro"

'Any other coding you want to run
End Sub


Note that there are many other events you can use to automatically activate
macros.
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Flipper" wrote:

Can a user write a mcaro that will automatically execute when the file is
opened?
--
Allan



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,722
Default write a macro to run a macro

Using the Workbook_Open event, you can either write your macro here, or you
can call it using Application.Run
Technically, it makes no difference. The advantage of placing the macro
somewhere else would be if its in another workbook, or you want to be able to
call it via other means (such as a button in your workbook.)

Now, to answer your question. You have the option of simply stating the
macro's name IF you've alwasy used distinct names (don't have same name macro
in module1 and module 2.)

If your macro name is "My_Macro" is in Module1, of workbook "My book.xls"
the 3 ways of calling the macro with increasing levels of refinement:

Application.Run ("MyMacro")
Application.Run ("Module1.MyMacro")
Application.Run ("'My book.xls'!Module1.MyMacro")

Callout which module/sheet you want if you have duplicate macro names.
Callout which workbook to use if calling a macro from another open workbook,
or the possibility exists that another open workbook has same macro name.

So, altogether

Private Sub Workbook_Open
Application.Run ("MyMacro")
'some other coding
MsgBox "Hi"
End Sub

This macro will cause the MyMacro to run when opened, and will then display
a msgbox. (illustrating the different ways to accomplish same goal)




--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Flipper" wrote:

Sorry, I am not understanding. Your verbiage "'Call a macro previously written
Application.Run "Book1!MyMacro"" waht does that mean? Do I insert the name of my Macro(s) here, or the name or my workbook? I presume that Book1!MyMacro would be the name of my macro? So does that mean Application.Run will execute it?

I'm very much a macro novice.
Thanks

--
Allan


"Luke M" wrote:

Yes. From the VBE, under the ThisWorkbook module, you can use something like
this:

Private Sub Workbook_Open()
'Call a macro previously written
Application.Run "Book1!MyMacro"

'Any other coding you want to run
End Sub


Note that there are many other events you can use to automatically activate
macros.
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Flipper" wrote:

Can a user write a mcaro that will automatically execute when the file is
opened?
--
Allan

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 51
Default write a macro to run a macro

Ok, thanks Luke. I did get Automatic Run to work, but it leads me to another
problem, which is that whatever worksheet that was active when I closed the
workbook is where the Automatic Run places the results of the macro, rather
than where the macro is supposed to go. As follows
The workbook contains about 20 separate worksheets. I have 2 macros, each
macro applies specifically to 1 worksheet. That, one macro performs a series
of steps where it opens another file, copies data, and then pastes that data
into that specific worksheet. When I added the Automatic Run, it pasted the
data into whatever worksheet was active when I previously closed the workbook.
--
Allan


"Luke M" wrote:

Using the Workbook_Open event, you can either write your macro here, or you
can call it using Application.Run
Technically, it makes no difference. The advantage of placing the macro
somewhere else would be if its in another workbook, or you want to be able to
call it via other means (such as a button in your workbook.)

Now, to answer your question. You have the option of simply stating the
macro's name IF you've alwasy used distinct names (don't have same name macro
in module1 and module 2.)

If your macro name is "My_Macro" is in Module1, of workbook "My book.xls"
the 3 ways of calling the macro with increasing levels of refinement:

Application.Run ("MyMacro")
Application.Run ("Module1.MyMacro")
Application.Run ("'My book.xls'!Module1.MyMacro")

Callout which module/sheet you want if you have duplicate macro names.
Callout which workbook to use if calling a macro from another open workbook,
or the possibility exists that another open workbook has same macro name.

So, altogether

Private Sub Workbook_Open
Application.Run ("MyMacro")
'some other coding
MsgBox "Hi"
End Sub

This macro will cause the MyMacro to run when opened, and will then display
a msgbox. (illustrating the different ways to accomplish same goal)




--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Flipper" wrote:

Sorry, I am not understanding. Your verbiage "'Call a macro previously written
Application.Run "Book1!MyMacro"" waht does that mean? Do I insert the name of my Macro(s) here, or the name or my workbook? I presume that Book1!MyMacro would be the name of my macro? So does that mean Application.Run will execute it?

I'm very much a macro novice.
Thanks

--
Allan


"Luke M" wrote:

Yes. From the VBE, under the ThisWorkbook module, you can use something like
this:

Private Sub Workbook_Open()
'Call a macro previously written
Application.Run "Book1!MyMacro"

'Any other coding you want to run
End Sub


Note that there are many other events you can use to automatically activate
macros.
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Flipper" wrote:

Can a user write a mcaro that will automatically execute when the file is
opened?
--
Allan

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default write a macro to run a macro

You have a couple of choices.

In your workbook_open code select the sheet you want then run the macro.

sub workbook_open()
Sheets("Sheet1").select
macroname
end sub

Or select the proper sheet in your macro.


Gord Dibben MS Excel MVP

On Fri, 14 Aug 2009 14:15:03 -0700, Flipper
wrote:

Ok, thanks Luke. I did get Automatic Run to work, but it leads me to another
problem, which is that whatever worksheet that was active when I closed the
workbook is where the Automatic Run places the results of the macro, rather
than where the macro is supposed to go. As follows
The workbook contains about 20 separate worksheets. I have 2 macros, each
macro applies specifically to 1 worksheet. That, one macro performs a series
of steps where it opens another file, copies data, and then pastes that data
into that specific worksheet. When I added the Automatic Run, it pasted the
data into whatever worksheet was active when I previously closed the workbook.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write a macro JStiehl Excel Discussion (Misc queries) 4 August 11th 08 10:08 PM
Can one VB macro write another macro? Gizmo63 Excel Worksheet Functions 1 May 9th 06 03:46 PM
How to write a macro?? Keeter Excel Discussion (Misc queries) 1 July 19th 05 08:34 PM
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? Daniel Excel Worksheet Functions 1 June 23rd 05 11:38 PM
Q: how can I write this macro? JIM.H. Excel Discussion (Misc queries) 6 May 30th 05 11:47 PM


All times are GMT +1. The time now is 09:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"