PC Review


Reply
Thread Tools Rate Thread

Automation:Selecting a different worksheet from another excel work

 
 
mattieflo
Guest
Posts: n/a
 
      22nd Apr 2008
Hello,

I have written the following code:

Dim appExcel as Excel.Application
Dim xlwb as Excel.Workbook
Set appExcel = New Excel.Application
Set xlwb =
appExcel.Workbooks.Open("\\F0862P1\share\compliance\orderedbed\issues
log.xls")
intTrackingNumber = xlwb.Worksheets(5).Range("A2").Value
xlwb.Worksheets(3).Range("A1").Select

Currently, the active worksheet in issues log.xls is the first worksheet. I
need it to select the 3 worksheet but it errors out on the last line of code
listed above giving me the "Select Method of range class failed.". If I go
into the issues log.xls workbook and save it when the 3rd worksheet is the
active sheet, the above code works fine. Does anyone have an idea what im
doing wrong?

Thanks!
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      22nd Apr 2008
You can only select a range on a worksheet that is selected.
You can only select a worksheet if the workbook is active.

You could use
xlwb.activate
xlwb.worksheets(3).select
xlwb.worksheets(3).range("a1").select

or

appexcel.goto xlwb.worksheets(3).range("a1") ', scroll:=true 'or false

But for most things, you don't need to select the range to work with it.

xlwb.worksheets(3).range("a1").value = "hi"

mattieflo wrote:
>
> Hello,
>
> I have written the following code:
>
> Dim appExcel as Excel.Application
> Dim xlwb as Excel.Workbook
> Set appExcel = New Excel.Application
> Set xlwb =
> appExcel.Workbooks.Open("\\F0862P1\share\compliance\orderedbed\issues
> log.xls")
> intTrackingNumber = xlwb.Worksheets(5).Range("A2").Value
> xlwb.Worksheets(3).Range("A1").Select
>
> Currently, the active worksheet in issues log.xls is the first worksheet. I
> need it to select the 3 worksheet but it errors out on the last line of code
> listed above giving me the "Select Method of range class failed.". If I go
> into the issues log.xls workbook and save it when the 3rd worksheet is the
> active sheet, the above code works fine. Does anyone have an idea what im
> doing wrong?
>
> Thanks!


--

Dave Peterson
 
Reply With Quote
 
mattieflo
Guest
Posts: n/a
 
      22nd Apr 2008
Thanks Dave,

appexcel.goto xlwb.worksheets(3).range("a1") ', scroll:=true 'or false

Worked like a charm.


"Dave Peterson" wrote:

> You can only select a range on a worksheet that is selected.
> You can only select a worksheet if the workbook is active.
>
> You could use
> xlwb.activate
> xlwb.worksheets(3).select
> xlwb.worksheets(3).range("a1").select
>
> or
>
> appexcel.goto xlwb.worksheets(3).range("a1") ', scroll:=true 'or false
>
> But for most things, you don't need to select the range to work with it.
>
> xlwb.worksheets(3).range("a1").value = "hi"
>
> mattieflo wrote:
> >
> > Hello,
> >
> > I have written the following code:
> >
> > Dim appExcel as Excel.Application
> > Dim xlwb as Excel.Workbook
> > Set appExcel = New Excel.Application
> > Set xlwb =
> > appExcel.Workbooks.Open("\\F0862P1\share\compliance\orderedbed\issues
> > log.xls")
> > intTrackingNumber = xlwb.Worksheets(5).Range("A2").Value
> > xlwb.Worksheets(3).Range("A1").Select
> >
> > Currently, the active worksheet in issues log.xls is the first worksheet. I
> > need it to select the 3 worksheet but it errors out on the last line of code
> > listed above giving me the "Select Method of range class failed.". If I go
> > into the issues log.xls workbook and save it when the 3rd worksheet is the
> > active sheet, the above code works fine. Does anyone have an idea what im
> > doing wrong?
> >
> > Thanks!

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Access Excel Automation, can I delete or rename a worksheet Stapes Microsoft Access 1 13th Sep 2007 12:07 PM
selecting values form multiple excel files into an excel worksheet =?Utf-8?B?bWFydGhh?= Microsoft Excel Programming 1 27th Jun 2005 10:17 AM
How to insert Excel Worksheet Name using Automation in VB Dot Net?? Vanessa Microsoft VB .NET 8 26th Aug 2003 09:06 PM
How to insert Excel Worksheet Name using Automation in VB Dot Net?? Vanessa Microsoft Dot NET 8 26th Aug 2003 09:06 PM
Re: How to insert Excel Worksheet Name using Automation in VB Dot Net?? Vanessa Microsoft Excel Programming 2 26th Aug 2003 03:57 PM


Features
 

Advertising
 

Newsgroups
 


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