Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 168
Default Open a File and Run AutoOpen Macro

I'm trying to use workbook.open to open another file and then I want this
other file to automatically run a macro. This other macro starts by closing
out the original file and then running a bunch of other code. I tried using
a Workbook_Open sub but as soon as the code closes the original file it just
stops running. I've tried everything I can think of but I cannot come up
with a solution. I need to open a specified file, then use this file to
close the original and run other code. Any ideas?

Thanks

Adam Bush
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 168
Default Open a File and Run AutoOpen Macro

Dustin,

I tried both of those suggestions and they didn't work? Any more ideas? Is
there any other information I can provide you with to narrow down the problem?

Thanks

Adam Bush

"dustinbrearton via OfficeKB.com" wrote:

If you also put a call to your Sub that you want to run in the Workbook_Open
sub it should continue on with the code. Try adding an error handler to the
code and see if that doesn't help.

On Error Resume Next

wrote:
I'm trying to use workbook.open to open another file and then I want this
other file to automatically run a macro. This other macro starts by closing
out the original file and then running a bunch of other code. I tried using
a Workbook_Open sub but as soon as the code closes the original file it just
stops running. I've tried everything I can think of but I cannot come up
with a solution. I need to open a specified file, then use this file to
close the original and run other code. Any ideas?

Thanks

Adam Bush


--
Message posted via
http://www.officekb.com


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Open a File and Run AutoOpen Macro

Why not just have the workbook_open() event in the first workbook close that
workbook?

Option Explicit
Private Sub Workbook_Open()

dim wkbk as workbook
set wkbk = workbooks.open(filename:="s:\ome\other\work\book.x ls")

me.close savechanges:=false

End Sub




wrote:

I'm trying to use workbook.open to open another file and then I want this
other file to automatically run a macro. This other macro starts by closing
out the original file and then running a bunch of other code. I tried using
a Workbook_Open sub but as soon as the code closes the original file it just
stops running. I've tried everything I can think of but I cannot come up
with a solution. I need to open a specified file, then use this file to
close the original and run other code. Any ideas?

Thanks

Adam Bush


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 168
Default Open a File and Run AutoOpen Macro

Dave,

The problem is I need to close the first workbook and then continue to run
code, so I can't do all this from the first workbook.

Bernie,

I tried your idea with the exact same results.

Any more ideas?

Thanks

Adam Bush

"Dave Peterson" wrote:

Why not just have the workbook_open() event in the first workbook close that
workbook?

Option Explicit
Private Sub Workbook_Open()

dim wkbk as workbook
set wkbk = workbooks.open(filename:="s:\ome\other\work\book.x ls")

me.close savechanges:=false

End Sub




wrote:

I'm trying to use workbook.open to open another file and then I want this
other file to automatically run a macro. This other macro starts by closing
out the original file and then running a bunch of other code. I tried using
a Workbook_Open sub but as soon as the code closes the original file it just
stops running. I've tried everything I can think of but I cannot come up
with a solution. I need to open a specified file, then use this file to
close the original and run other code. Any ideas?

Thanks

Adam Bush


--

Dave Peterson



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Open a File and Run AutoOpen Macro

Try

Workbooks.Open FileName:="whatever.XLS"
ActiveWorkbook.RunAutoMacros xlAutoOpen

With the file opened having a macro like so:

Sub Auto_Open()
'Some code to do stuff here
End Sub


HTH,
Bernie
MS Excel MVP


" m wrote in message
...
I'm trying to use workbook.open to open another file and then I want this
other file to automatically run a macro. This other macro starts by closing
out the original file and then running a bunch of other code. I tried using
a Workbook_Open sub but as soon as the code closes the original file it just
stops running. I've tried everything I can think of but I cannot come up
with a solution. I need to open a specified file, then use this file to
close the original and run other code. Any ideas?

Thanks

Adam Bush



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Open a File and Run AutoOpen Macro

Am I right in understanding the problem as follows?

Workbook 1 open with code opens Workbook2.
Once Workbook2 opens it closes Workbook 1.

If that's the case, surely the reason it stops working is that the code no
longer exists because the sheet is closed.

" wrote:

I'm trying to use workbook.open to open another file and then I want this
other file to automatically run a macro. This other macro starts by closing
out the original file and then running a bunch of other code. I tried using
a Workbook_Open sub but as soon as the code closes the original file it just
stops running. I've tried everything I can think of but I cannot come up
with a solution. I need to open a specified file, then use this file to
close the original and run other code. Any ideas?

Thanks

Adam Bush

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 168
Default Open a File and Run AutoOpen Macro

Wullie,

Workbook1 opens workbook2. Workbook 2 then closes workbook1 and runs a
bunch of other code. Also, after this code is run from workbook2, workbook1
is reopened and workbook 2 is closed. The whole reason for this is I want to
just have workbook1 open at all times except when the code's running, however
for the code to be run correct workbook1 needs to be closed for a period of
time. Any ideas?

Thanks

Adam Bush

"Wullie" wrote:

Am I right in understanding the problem as follows?

Workbook 1 open with code opens Workbook2.
Once Workbook2 opens it closes Workbook 1.

If that's the case, surely the reason it stops working is that the code no
longer exists because the sheet is closed.

" wrote:

I'm trying to use workbook.open to open another file and then I want this
other file to automatically run a macro. This other macro starts by closing
out the original file and then running a bunch of other code. I tried using
a Workbook_Open sub but as soon as the code closes the original file it just
stops running. I've tried everything I can think of but I cannot come up
with a solution. I need to open a specified file, then use this file to
close the original and run other code. Any ideas?

Thanks

Adam Bush

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Open a File and Run AutoOpen Macro

But the code exists within workbook1.

Therefore, once you open workbook2 and closed workbook1, the code no longer
exists to run. Does that make sense?

Can you write this code in a separate workbook that you can leave open?

eg Workbook1 holds what it currently holds without the code, workbook3 holds
the code - both are open.
The code is run from workbook3, closes workbook1, opens workbook2, does what
is required, closes workbook2 then reopens workbook1, all the while workbook3
remains open.

" wrote:

I'm trying to use workbook.open to open another file and then I want this
other file to automatically run a macro. This other macro starts by closing
out the original file and then running a bunch of other code. I tried using
a Workbook_Open sub but as soon as the code closes the original file it just
stops running. I've tried everything I can think of but I cannot come up
with a solution. I need to open a specified file, then use this file to
close the original and run other code. Any ideas?

Thanks

Adam Bush



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
Autoopen of an Excel File at the set time mrbalaje Excel Programming 2 May 8th 07 04:41 AM
Open a file do a macro ( made) and open next succesive file SVTman74 Excel Programming 5 April 21st 06 10:14 PM
Macro to call a file that has a auto open macro in the file itself [email protected] Excel Programming 1 August 5th 05 06:39 AM
'Yes' 'No' button on autoopen macro Larry Excel Programming 2 May 21st 04 09:59 PM


All times are GMT +1. The time now is 07:13 AM.

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

About Us

"It's about Microsoft Excel"