Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Works at one place but not another?

Hello everyone,

Basically, a sub-routine 'ResetImportSection' is called twice in the
VBA code. However it works well for the first one but fires a 'runtime
error 1004: Select method of Range class failed.' at the second place.
ResetImportSection is used to tidy up in case of an import failure. It
is called if the import file is corrupted somehow in the 1st instance
and it works fine. The other piece of code also calls it when too many
days are involved(at most 7 days). That's where it crashs over the
following stagement within ResetImportSection:

'Select the range to be cleared
masterworkbook.Sheets("Shipper").Range("G8:G12").S elect

But it continues to run(since I can see the pane is cleared as desired)
if I click the 'continue' button afterwards.

Can why does it crash when it is invoked in the secone case? Thanks go
to any posts.

Regards
Frank

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Works at one place but not another?

If masterworkbook.Sheets("Shipper") isn't the activesheet, then you would
have that problem.

--
Regards,
Tom Ogilvy

"OrientalPearl" wrote in message
ups.com...
Hello everyone,

Basically, a sub-routine 'ResetImportSection' is called twice in the
VBA code. However it works well for the first one but fires a 'runtime
error 1004: Select method of Range class failed.' at the second place.
ResetImportSection is used to tidy up in case of an import failure. It
is called if the import file is corrupted somehow in the 1st instance
and it works fine. The other piece of code also calls it when too many
days are involved(at most 7 days). That's where it crashs over the
following stagement within ResetImportSection:

'Select the range to be cleared
masterworkbook.Sheets("Shipper").Range("G8:G12").S elect

But it continues to run(since I can see the pane is cleared as desired)
if I click the 'continue' button afterwards.

Can why does it crash when it is invoked in the secone case? Thanks go
to any posts.

Regards
Frank



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Works at one place but not another?

Thanks Tom for your reply. Sorry for not mentioning that the whole
workbook has been set active right before the selection statement.

'Set up masterworkbook
Dim masterworkbook As Workbook
Set masterworkbook = ActiveWorkbook

'Select the range to be cleared
masterworkbook.Sheets("Shipper").Range("G8:G12").S elect

It's worthwhile noting that the same routine does work in the first
scenario(when the import file is corrupted; whenever a bad file format
is imported, it is invoked and executed without error), but not in the
second one. That's why I feel so perplexed. =S

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Works at one place but not another?

What you have offered has nothing to do with what I said. Changing the
activesheet is as easy as doing

Worksheets("Dog").Activate

You can not select except on the activesheet. If you are opening a file, it
is highly probably (without seeing your code- but reinforced by the fact
that you are even attempting to select that range) that Shipper is not the
activesheet, no matter how many references you might have set to workbook
that contains it.

--
Regards,
Tom Ogilvy

"OrientalPearl" wrote in message
oups.com...
Thanks Tom for your reply. Sorry for not mentioning that the whole
workbook has been set active right before the selection statement.

'Set up masterworkbook
Dim masterworkbook As Workbook
Set masterworkbook = ActiveWorkbook

'Select the range to be cleared
masterworkbook.Sheets("Shipper").Range("G8:G12").S elect

It's worthwhile noting that the same routine does work in the first
scenario(when the import file is corrupted; whenever a bad file format
is imported, it is invoked and executed without error), but not in the
second one. That's why I feel so perplexed. =S



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Works at one place but not another?

You're purely correct, Tom. Explicit activition of the worksheet is the
key. Though (quoted from my another post):

'Not sure why explicit activition of the worksheet is required since
every selection statement started with
'masterworkbook.Sheets("Shipper").Range...'. Still not sure why the
same
sub-routine behaved differently when being invoked. '


Thanks and regards
Frank



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Works at one place but not another?

Sorry to say, but
If they said that that just reinforces that you were talking to the wrong
person.

--
Regards,
Tom Ogilvy

"OrientalPearl" wrote in message
oups.com...
You're purely correct, Tom. Explicit activition of the worksheet is the
key. Though (quoted from my another post):

'Not sure why explicit activition of the worksheet is required since
every selection statement started with
'masterworkbook.Sheets("Shipper").Range...'. Still not sure why the
same
sub-routine behaved differently when being invoked. '


Thanks and regards
Frank



  #7   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Works at one place but not another?

I don't know exactly why, but I think you have to break the statement up.
(It's just a guess, but maybe something to do with a workbook object not
having a select method precludes you from including it in the statement??)

MasterWorkBook.Activate
Sheets("Shipper").Range("G8:G12").Select

Or, you could try to clear the range w/o selecting it.
masterworkbook.Sheets("Shipper").Range("G8:G12").C lear

"OrientalPearl" wrote:

Hello everyone,

Basically, a sub-routine 'ResetImportSection' is called twice in the
VBA code. However it works well for the first one but fires a 'runtime
error 1004: Select method of Range class failed.' at the second place.
ResetImportSection is used to tidy up in case of an import failure. It
is called if the import file is corrupted somehow in the 1st instance
and it works fine. The other piece of code also calls it when too many
days are involved(at most 7 days). That's where it crashs over the
following stagement within ResetImportSection:

'Select the range to be cleared
masterworkbook.Sheets("Shipper").Range("G8:G12").S elect

But it continues to run(since I can see the pane is cleared as desired)
if I click the 'continue' button afterwards.

Can why does it crash when it is invoked in the secone case? Thanks go
to any posts.

Regards
Frank


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Works at one place but not another?

Thanks JMB for your post. The workbook has originally been set as
active. Your second solution works, i.e. Act without prior selection,
requiring modification to all selection statements. I found it solves
the problem by setting the specific worksheet, not workbook, active,
i.e. adding the following command prior to the group of selection
statements(Sorry, it clears up other relevant ranges as well besides
the one provided in my 1st post):

masterworkbook.Sheets("Shipper").Activate

Not sure why explicit activition of the worksheet is required since
every selection statement started with
'masterworkbook.Sheets("Shipper").Range...'. Still not sure why the
sub-routine behaved differently when being invoked.

Thanks to you both and regards
Frank

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Works at one place but not another?

works fine for me as long as the sheet is active: (as demo'd from the
immediate window)

set masterworkbook = Activeworkbook
masterworkbook.Sheets("Shipper").Range("G8:G12").s elect
? selection.Address(external:=True)
[Book1]Shipper!$G$8:$G$12


If Shipper isn't the active sheet, then of course it will not work. If
activating MasterWorkbook makes Shipper that activesheet, then it would work
by breaking it up. If not then you would need to break it up againg

Masterworkbook.Activate
Worksheets("Shipper").Activate
Range("G8:G12").Select

or

Application.Goto masterworkbook.Sheets("Shipper").Range("G8:G12")

--
Regards,
Tom Ogilvy




"JMB" wrote in message
...
I don't know exactly why, but I think you have to break the statement up.
(It's just a guess, but maybe something to do with a workbook object not
having a select method precludes you from including it in the statement??)

MasterWorkBook.Activate
Sheets("Shipper").Range("G8:G12").Select

Or, you could try to clear the range w/o selecting it.
masterworkbook.Sheets("Shipper").Range("G8:G12").C lear

"OrientalPearl" wrote:

Hello everyone,

Basically, a sub-routine 'ResetImportSection' is called twice in the
VBA code. However it works well for the first one but fires a 'runtime
error 1004: Select method of Range class failed.' at the second place.
ResetImportSection is used to tidy up in case of an import failure. It
is called if the import file is corrupted somehow in the 1st instance
and it works fine. The other piece of code also calls it when too many
days are involved(at most 7 days). That's where it crashs over the
following stagement within ResetImportSection:

'Select the range to be cleared
masterworkbook.Sheets("Shipper").Range("G8:G12").S elect

But it continues to run(since I can see the pane is cleared as desired)
if I click the 'continue' button afterwards.

Can why does it crash when it is invoked in the secone case? Thanks go
to any posts.

Regards
Frank




  #10   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Works at one place but not another?

You are correct. When I was playing with it, my target worksheet must have
been the activesheet when I activated the workbook (as you probably
suspected).

"Tom Ogilvy" wrote:

works fine for me as long as the sheet is active: (as demo'd from the
immediate window)

set masterworkbook = Activeworkbook
masterworkbook.Sheets("Shipper").Range("G8:G12").s elect
? selection.Address(external:=True)
[Book1]Shipper!$G$8:$G$12


If Shipper isn't the active sheet, then of course it will not work. If
activating MasterWorkbook makes Shipper that activesheet, then it would work
by breaking it up. If not then you would need to break it up againg

Masterworkbook.Activate
Worksheets("Shipper").Activate
Range("G8:G12").Select

or

Application.Goto masterworkbook.Sheets("Shipper").Range("G8:G12")

--
Regards,
Tom Ogilvy




"JMB" wrote in message
...
I don't know exactly why, but I think you have to break the statement up.
(It's just a guess, but maybe something to do with a workbook object not
having a select method precludes you from including it in the statement??)

MasterWorkBook.Activate
Sheets("Shipper").Range("G8:G12").Select

Or, you could try to clear the range w/o selecting it.
masterworkbook.Sheets("Shipper").Range("G8:G12").C lear

"OrientalPearl" wrote:

Hello everyone,

Basically, a sub-routine 'ResetImportSection' is called twice in the
VBA code. However it works well for the first one but fires a 'runtime
error 1004: Select method of Range class failed.' at the second place.
ResetImportSection is used to tidy up in case of an import failure. It
is called if the import file is corrupted somehow in the 1st instance
and it works fine. The other piece of code also calls it when too many
days are involved(at most 7 days). That's where it crashs over the
following stagement within ResetImportSection:

'Select the range to be cleared
masterworkbook.Sheets("Shipper").Range("G8:G12").S elect

But it continues to run(since I can see the pane is cleared as desired)
if I click the 'continue' button afterwards.

Can why does it crash when it is invoked in the secone case? Thanks go
to any posts.

Regards
Frank







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
No place for sum [email protected] Excel Worksheet Functions 4 March 28th 07 02:52 AM
Excel Addin works that works on a template workbook s.jay_k Excel Programming 0 February 15th 06 07:31 PM
This place ROX!! brodiemac Excel Discussion (Misc queries) 0 December 22nd 05 03:21 PM
it works, it doesn work, its works....and so on. Naz Excel Programming 6 September 30th 05 01:52 PM
How do I convert works file to excel without works software? CatMB Excel Discussion (Misc queries) 1 June 21st 05 04:12 PM


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