Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Programmatically selecting first worksheet

I have a list of workbooks and I want to get some data off of the first
worksheet. I plan to open the file and use an indirect formula similar to
what I'm showing below:

Range("H" & i).Select
ActiveCell.FormulaR1C1 = "=""'""&RC1&""\[""&RC7&""]SHEET1'!"""
Range("I" & i).Select
ActiveCell.FormulaR1C1 = "=INDIRECT(RC[-1]&""$B$33"")"


UNFORTUNATELY, the first worksheet has different names in each workbook.
It's not SHEET1. How would I identify the sheetname and include it in my
formula?

Thanks,
Barb Reinhardt

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Programmatically selecting first worksheet

sName = Activeworkbook.Worksheets(1).Name

or if your linking to a different workbook

sName = "'[" & activeworkbook.name & "]" & activeworkbook.worksheets(1).Name
& "'!R1C1"



--
Regards,
Tom Ogilvy


"Barb Reinhardt" wrote:

I have a list of workbooks and I want to get some data off of the first
worksheet. I plan to open the file and use an indirect formula similar to
what I'm showing below:

Range("H" & i).Select
ActiveCell.FormulaR1C1 = "=""'""&RC1&""\[""&RC7&""]SHEET1'!"""
Range("I" & i).Select
ActiveCell.FormulaR1C1 = "=INDIRECT(RC[-1]&""$B$33"")"


UNFORTUNATELY, the first worksheet has different names in each workbook.
It's not SHEET1. How would I identify the sheetname and include it in my
formula?

Thanks,
Barb Reinhardt

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Programmatically selecting first worksheet

I have this now:

Set oWB = Workbooks.Open(Cells(i, "B"), ReadOnly = True, UpdateLinks
= False)
aWB.Activate
aWS.Activate
sName = oWB.Worksheets(1).Name

Cells(i, "H").FormulaR1C1 = "=""'""&RC1&""\[""&RC7&""]""&sName&""'!"""

I get an error because it doesn't know what sName is. I have dimensioned
sName as a string.

What next?

Thanks,
Barb Reinhardt

"Tom Ogilvy" wrote:

sName = Activeworkbook.Worksheets(1).Name

or if your linking to a different workbook

sName = "'[" & activeworkbook.name & "]" & activeworkbook.worksheets(1).Name
& "'!R1C1"



--
Regards,
Tom Ogilvy


"Barb Reinhardt" wrote:

I have a list of workbooks and I want to get some data off of the first
worksheet. I plan to open the file and use an indirect formula similar to
what I'm showing below:

Range("H" & i).Select
ActiveCell.FormulaR1C1 = "=""'""&RC1&""\[""&RC7&""]SHEET1'!"""
Range("I" & i).Select
ActiveCell.FormulaR1C1 = "=INDIRECT(RC[-1]&""$B$33"")"


UNFORTUNATELY, the first worksheet has different names in each workbook.
It's not SHEET1. How would I identify the sheetname and include it in my
formula?

Thanks,
Barb Reinhardt

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Programmatically selecting first worksheet

The indirect formula will break when you close the sending workbook.

Why not just retrieve the value?

somesheet.range("H" & i).value = oWB.worksheets(1).range("B33").value

or

owb.worksheets(1).range("b33").copy _
destination:=somesheet.range("h" & i)

========
If you were building a formula to just retrieve that value (after the workbook
is closed), you could do something like:

somesheet.range("H" & i).formula _
= "=" & owb.worksheets(1).range("b33").address(external:=t rue)

========

But I'm not sure what you're doing...



Barb Reinhardt wrote:

I have this now:

Set oWB = Workbooks.Open(Cells(i, "B"), ReadOnly = True, UpdateLinks
= False)
aWB.Activate
aWS.Activate
sName = oWB.Worksheets(1).Name

Cells(i, "H").FormulaR1C1 = "=""'""&RC1&""\[""&RC7&""]""&sName&""'!"""

I get an error because it doesn't know what sName is. I have dimensioned
sName as a string.

What next?

Thanks,
Barb Reinhardt

"Tom Ogilvy" wrote:

sName = Activeworkbook.Worksheets(1).Name

or if your linking to a different workbook

sName = "'[" & activeworkbook.name & "]" & activeworkbook.worksheets(1).Name
& "'!R1C1"



--
Regards,
Tom Ogilvy


"Barb Reinhardt" wrote:

I have a list of workbooks and I want to get some data off of the first
worksheet. I plan to open the file and use an indirect formula similar to
what I'm showing below:

Range("H" & i).Select
ActiveCell.FormulaR1C1 = "=""'""&RC1&""\[""&RC7&""]SHEET1'!"""
Range("I" & i).Select
ActiveCell.FormulaR1C1 = "=INDIRECT(RC[-1]&""$B$33"")"


UNFORTUNATELY, the first worksheet has different names in each workbook.
It's not SHEET1. How would I identify the sheetname and include it in my
formula?

Thanks,
Barb Reinhardt


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Programmatically selecting first worksheet

Or paste|special|Values

(whatever you need???)

Dave Peterson wrote:

The indirect formula will break when you close the sending workbook.

Why not just retrieve the value?

somesheet.range("H" & i).value = oWB.worksheets(1).range("B33").value

or

owb.worksheets(1).range("b33").copy _
destination:=somesheet.range("h" & i)

========
If you were building a formula to just retrieve that value (after the workbook
is closed), you could do something like:

somesheet.range("H" & i).formula _
= "=" & owb.worksheets(1).range("b33").address(external:=t rue)

========

But I'm not sure what you're doing...

Barb Reinhardt wrote:

I have this now:

Set oWB = Workbooks.Open(Cells(i, "B"), ReadOnly = True, UpdateLinks
= False)
aWB.Activate
aWS.Activate
sName = oWB.Worksheets(1).Name

Cells(i, "H").FormulaR1C1 = "=""'""&RC1&""\[""&RC7&""]""&sName&""'!"""

I get an error because it doesn't know what sName is. I have dimensioned
sName as a string.

What next?

Thanks,
Barb Reinhardt

"Tom Ogilvy" wrote:

sName = Activeworkbook.Worksheets(1).Name

or if your linking to a different workbook

sName = "'[" & activeworkbook.name & "]" & activeworkbook.worksheets(1).Name
& "'!R1C1"



--
Regards,
Tom Ogilvy


"Barb Reinhardt" wrote:

I have a list of workbooks and I want to get some data off of the first
worksheet. I plan to open the file and use an indirect formula similar to
what I'm showing below:

Range("H" & i).Select
ActiveCell.FormulaR1C1 = "=""'""&RC1&""\[""&RC7&""]SHEET1'!"""
Range("I" & i).Select
ActiveCell.FormulaR1C1 = "=INDIRECT(RC[-1]&""$B$33"")"


UNFORTUNATELY, the first worksheet has different names in each workbook.
It's not SHEET1. How would I identify the sheetname and include it in my
formula?

Thanks,
Barb Reinhardt


--

Dave Peterson


--

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
Programmatically selecting first worksheet Barb Reinhardt Excel Programming 1 July 14th 06 12:38 AM
Selecting Embedded charts in Active Sheets programmatically Barb Reinhardt Charts and Charting in Excel 5 January 15th 06 02:36 PM
Selecting most of very many programmatically Tony Rizzo[_2_] Excel Programming 2 July 27th 05 08:50 PM
Programmatically Add Worksheet Event The Vision Thing Excel Programming 1 September 2nd 04 02:14 AM
Selecting Rows Programmatically Aaron Lampkin Excel Programming 1 September 5th 03 01:42 PM


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