Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Automation:Selecting a different worksheet from another excel work

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\complianc e\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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Automation:Selecting a different worksheet from another excel work

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\complianc e\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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Automation:Selecting a different worksheet from another excel

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\complianc e\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
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
Excel Macro: Selecting items from another worksheet withoutactivating it [email protected] Excel Programming 2 January 19th 08 03:42 AM
Automation : Excel::Font : get_Font does not work vince Excel Programming 1 February 19th 06 12:59 AM
Selecting an Excel tab, Delete Worksheet command is not active missyjes New Users to Excel 1 September 23rd 05 03:16 PM
Problem with optional parameters in Excel Automation Add-in worksheet function Mike Gilkeson Excel Programming 0 February 18th 04 02:13 PM
How to insert Excel Worksheet Name using Automation in VB Dot Net?? Vanessa[_2_] Excel Programming 2 August 26th 03 03:57 PM


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