Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Giving Macro control to another workbook

I am trying to write a macro that will check to see if a newer version of the
workbook that is being run exists. If it does, my thought was to pass control
to a second workbook, close the first, copy/update the first workbook and
restart the first workbook and finally close out the second.

While I understand how to run a macro in another workbook, if I close the
first workbook the second workbook macros just stop. Below is my code
example, any ideas? Or indeed is there a much smarter way to do this? Because
of course this will cause the Enable macro's message several times.

In Workbook1:

Sub Start()
Workbooks.Open Filename:="Workbook2.xls"
Run "Workbook2.xls" & "!MyMacro2", param1, param2, param3
ThisWorkbook.Close SaveChanges:=False
End Sub

Sub MyMacro1()
' continue doing stuff
End Sub


In Workbook2:

Sub MyMacro2(param1, param2, param3)
' Do stuff
Workbooks.Open Filename:="Workbook1.xls"
Run "Workbook1.xls" & "!MyMacro1"
ThisWorkbook.Close SaveChanges:=False
End Sub

--
Trefor
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Giving Macro control to another workbook

Why not put a routine in Personal or an add-in that does the checking.
It can use the Activeworkbook as the "old" version then make your check for
a newer one based on filename or however you do it now.
If this code finds a newer version, close the "old" and open the new, may be
with a Kill of the old and a move of the new, if necessary.
Less conflict.

NickHK

"Trefor" wrote in message
...
I am trying to write a macro that will check to see if a newer version of

the
workbook that is being run exists. If it does, my thought was to pass

control
to a second workbook, close the first, copy/update the first workbook and
restart the first workbook and finally close out the second.

While I understand how to run a macro in another workbook, if I close the
first workbook the second workbook macros just stop. Below is my code
example, any ideas? Or indeed is there a much smarter way to do this?

Because
of course this will cause the Enable macro's message several times.

In Workbook1:

Sub Start()
Workbooks.Open Filename:="Workbook2.xls"
Run "Workbook2.xls" & "!MyMacro2", param1, param2, param3
ThisWorkbook.Close SaveChanges:=False
End Sub

Sub MyMacro1()
' continue doing stuff
End Sub


In Workbook2:

Sub MyMacro2(param1, param2, param3)
' Do stuff
Workbooks.Open Filename:="Workbook1.xls"
Run "Workbook1.xls" & "!MyMacro1"
ThisWorkbook.Close SaveChanges:=False
End Sub

--
Trefor



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Giving Macro control to another workbook

NickHK,

Many thanks for your reply. An interesting thought, but I need to distribute
this application and that means being in control of my app on someone elses
machine.

--
Trefor


"NickHK" wrote:

Why not put a routine in Personal or an add-in that does the checking.
It can use the Activeworkbook as the "old" version then make your check for
a newer one based on filename or however you do it now.
If this code finds a newer version, close the "old" and open the new, may be
with a Kill of the old and a move of the new, if necessary.
Less conflict.

NickHK

"Trefor" wrote in message
...
I am trying to write a macro that will check to see if a newer version of

the
workbook that is being run exists. If it does, my thought was to pass

control
to a second workbook, close the first, copy/update the first workbook and
restart the first workbook and finally close out the second.

While I understand how to run a macro in another workbook, if I close the
first workbook the second workbook macros just stop. Below is my code
example, any ideas? Or indeed is there a much smarter way to do this?

Because
of course this will cause the Enable macro's message several times.

In Workbook1:

Sub Start()
Workbooks.Open Filename:="Workbook2.xls"
Run "Workbook2.xls" & "!MyMacro2", param1, param2, param3
ThisWorkbook.Close SaveChanges:=False
End Sub

Sub MyMacro1()
' continue doing stuff
End Sub


In Workbook2:

Sub MyMacro2(param1, param2, param3)
' Do stuff
Workbooks.Open Filename:="Workbook1.xls"
Run "Workbook1.xls" & "!MyMacro1"
ThisWorkbook.Close SaveChanges:=False
End Sub

--
Trefor




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Giving Macro control to another workbook

Yes, so you can place an xls in their start folder, create an add-in etc do
the management of your files.
Otherwise every file you send will have to have the file checking code
included in itself, which seems a waste.

NickHK

"Trefor" wrote in message
...
NickHK,

Many thanks for your reply. An interesting thought, but I need to

distribute
this application and that means being in control of my app on someone

elses
machine.

--
Trefor


"NickHK" wrote:

Why not put a routine in Personal or an add-in that does the checking.
It can use the Activeworkbook as the "old" version then make your check

for
a newer one based on filename or however you do it now.
If this code finds a newer version, close the "old" and open the new,

may be
with a Kill of the old and a move of the new, if necessary.
Less conflict.

NickHK

"Trefor" wrote in message
...
I am trying to write a macro that will check to see if a newer version

of
the
workbook that is being run exists. If it does, my thought was to pass

control
to a second workbook, close the first, copy/update the first workbook

and
restart the first workbook and finally close out the second.

While I understand how to run a macro in another workbook, if I close

the
first workbook the second workbook macros just stop. Below is my code
example, any ideas? Or indeed is there a much smarter way to do this?

Because
of course this will cause the Enable macro's message several times.

In Workbook1:

Sub Start()
Workbooks.Open Filename:="Workbook2.xls"
Run "Workbook2.xls" & "!MyMacro2", param1, param2, param3
ThisWorkbook.Close SaveChanges:=False
End Sub

Sub MyMacro1()
' continue doing stuff
End Sub


In Workbook2:

Sub MyMacro2(param1, param2, param3)
' Do stuff
Workbooks.Open Filename:="Workbook1.xls"
Run "Workbook1.xls" & "!MyMacro1"
ThisWorkbook.Close SaveChanges:=False
End Sub

--
Trefor






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
Very large workbook now giving incorrect results :( [email protected] Excel Discussion (Misc queries) 0 July 17th 06 11:29 PM
Very large complex workbook is now giving me the wrong results :( S Davis Excel Worksheet Functions 0 July 17th 06 09:00 PM
Macro giving errors at workbook open kcdonaldson Excel Discussion (Misc queries) 1 December 6th 05 04:15 PM
Why isn't this macro giving me proper results? Girish Excel Programming 3 September 9th 05 06:56 PM
Macro is giving me problems with sorting Charlene Dallos Excel Programming 3 September 2nd 03 07:02 PM


All times are GMT +1. The time now is 06:56 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"