Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 28
Default Opening a file stops a Macro

My spreadsheet (main.xls) has a number of macros. One of them (macro1)
tries to open another spreadsheet (file.xls). However, when file.xls opens,
the macro stops, rather than continuing with the rest of its code. I have
similar code in macro2, but it seems to work as expected.

An excerpt from macro1 code:
..
ChDir (ActiveWorkbook.Path) ' main.xls and file.xls are
in the same folder on C:
..
Workbooks.Open (file.xls) ' file.xls does not
include the path
x = 1
..
Running macro1, file.xls opens and macro1 stops. If the breakpoint is set
on the x = 1 line, execution never gets there.

If the Breakpoint is set on the Open line, execution halts there, but
pressing F8 (or F5) will cause macro1 to continue normally. Normally
includes executing similar code farther on in macro1.

Any suggestions? I've tried everything I can think of. FYI, I'm fairly new
to Excel, and particularly to VBA. I am experienced in several forms of
Basic, and a couple other high level languages.

Perhaps there's a workaround. All I really want to do is open file.xls,
copy a little bit of stuff into it, and then close it. I plan on doing this
to half a dozen files.xls.

Respectfully submitted,
Bob Myers


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 185
Default Opening a file stops a Macro

Bob

VBA runs sequentially and therefore I would suspect that the workbook you
are opening is trying to get input from the user or similar. Until that
happens the code will not continue. Do you have alerts switched off in the
code or screenupdating off? This may hide something the workbook opening
wants to do

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
DTHIS
web:
www.nickhodge.co.uk




"Bob Myers" wrote in message
...
My spreadsheet (main.xls) has a number of macros. One of them (macro1)
tries to open another spreadsheet (file.xls). However, when file.xls
opens,
the macro stops, rather than continuing with the rest of its code. I have
similar code in macro2, but it seems to work as expected.

An excerpt from macro1 code:
.
ChDir (ActiveWorkbook.Path) ' main.xls and file.xls are
in the same folder on C:
.
Workbooks.Open (file.xls) ' file.xls does not
include the path
x = 1
.
Running macro1, file.xls opens and macro1 stops. If the breakpoint is set
on the x = 1 line, execution never gets there.

If the Breakpoint is set on the Open line, execution halts there, but
pressing F8 (or F5) will cause macro1 to continue normally. Normally
includes executing similar code farther on in macro1.

Any suggestions? I've tried everything I can think of. FYI, I'm fairly
new
to Excel, and particularly to VBA. I am experienced in several forms of
Basic, and a couple other high level languages.

Perhaps there's a workaround. All I really want to do is open file.xls,
copy a little bit of stuff into it, and then close it. I plan on doing
this
to half a dozen files.xls.

Respectfully submitted,
Bob Myers


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Opening a file stops a Macro

My guess is that you're using a shortcut key to start your macro. And that
shortcut key includes a shift key.

Remove the shift key from that shortcut combination and try it again.

Holding the shiftkey when you open a workbook stops the open macros from
running. It also confuses excel/vba into thinking it should stop.

Bob Myers wrote:

My spreadsheet (main.xls) has a number of macros. One of them (macro1)
tries to open another spreadsheet (file.xls). However, when file.xls opens,
the macro stops, rather than continuing with the rest of its code. I have
similar code in macro2, but it seems to work as expected.

An excerpt from macro1 code:
.
ChDir (ActiveWorkbook.Path) ' main.xls and file.xls are
in the same folder on C:
.
Workbooks.Open (file.xls) ' file.xls does not
include the path
x = 1
.
Running macro1, file.xls opens and macro1 stops. If the breakpoint is set
on the x = 1 line, execution never gets there.

If the Breakpoint is set on the Open line, execution halts there, but
pressing F8 (or F5) will cause macro1 to continue normally. Normally
includes executing similar code farther on in macro1.

Any suggestions? I've tried everything I can think of. FYI, I'm fairly new
to Excel, and particularly to VBA. I am experienced in several forms of
Basic, and a couple other high level languages.

Perhaps there's a workaround. All I really want to do is open file.xls,
copy a little bit of stuff into it, and then close it. I plan on doing this
to half a dozen files.xls.

Respectfully submitted,
Bob Myers


--

Dave Peterson
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
Can a macro be run on opening the file? Cortez Excel Discussion (Misc queries) 3 March 8th 07 08:34 PM
Can a macro be run on opening the file? Cortez Excel Discussion (Misc queries) 0 March 8th 07 04:57 PM
Formula stops working after re-opening worksheet watchtower Excel Worksheet Functions 2 November 20th 06 09:11 PM
Opening a file with a Macro Adam1 Chicago Excel Discussion (Misc queries) 2 February 28th 05 10:13 PM
After deleting a macro, I still get the pop-up when opening file Anne Excel Worksheet Functions 2 December 8th 04 05:31 PM


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

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"