Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default How do you extract the VB name for a sheet in another file?

I know I can name sheets in the proptery window under the Name property.

So if i write a macro in Worbook1 refering to a sheet in Workbook1 that I
named "ThisfileSheet1VbNm I can say:

ThisfileSheet1VbNm.Range("A1").Select

But how do I refer to the name of a sheet in another workbook (workbook2),
within my code in workbook 1. If I have a sheet named "OtherfileSheet1VbNm"
in workbook 2, and I want to - upon opening workbook2 within macro in
workbook1- select this sheet the following code gives me an error: "Variable
not Defined"

OtherfileSheet1VbNm.Select

How do inform my code that this named sheet exists in the workbook I have
jsut opened?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default How do you extract the VB name for a sheet in another file?

Usually the workbook you just opened will be active. In that case,

ActiveWorkbook.Sheets("OtherSheetName").Range("wha tever").select

If you need to activate it first then:

Workbooks("Workbook2").Activate
ActiveWorkbook.Sheets("YourSheetName").Range("what ever").Select

HTH.

"ExcelMonkey" wrote:

I know I can name sheets in the proptery window under the Name property.

So if i write a macro in Worbook1 refering to a sheet in Workbook1 that I
named "ThisfileSheet1VbNm I can say:

ThisfileSheet1VbNm.Range("A1").Select

But how do I refer to the name of a sheet in another workbook (workbook2),
within my code in workbook 1. If I have a sheet named "OtherfileSheet1VbNm"
in workbook 2, and I want to - upon opening workbook2 within macro in
workbook1- select this sheet the following code gives me an error: "Variable
not Defined"

OtherfileSheet1VbNm.Select

How do inform my code that this named sheet exists in the workbook I have
jsut opened?

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default How do you extract the VB name for a sheet in another file?

When I try to run the doe I get an error on the line:

TemplateVbNm.Select

This error occurs before the code even runs. You can see that I do attempt
to activate the file first but since the error ocurrs before the code runs,
the activate Method never gets a change to trigger. You can also see the
line of code above the failed line is commented out. This line has the
actuall sheet name in it. However I do not want to use this name as the user
may want to change it.

Windows(ExtractedFileName).Activate
'Worksheets("Template").Select
TemplateVbNm.Select

Thanks

"quartz" wrote:

Usually the workbook you just opened will be active. In that case,

ActiveWorkbook.Sheets("OtherSheetName").Range("wha tever").select

If you need to activate it first then:

Workbooks("Workbook2").Activate
ActiveWorkbook.Sheets("YourSheetName").Range("what ever").Select

HTH.

"ExcelMonkey" wrote:

I know I can name sheets in the proptery window under the Name property.

So if i write a macro in Worbook1 refering to a sheet in Workbook1 that I
named "ThisfileSheet1VbNm I can say:

ThisfileSheet1VbNm.Range("A1").Select

But how do I refer to the name of a sheet in another workbook (workbook2),
within my code in workbook 1. If I have a sheet named "OtherfileSheet1VbNm"
in workbook 2, and I want to - upon opening workbook2 within macro in
workbook1- select this sheet the following code gives me an error: "Variable
not Defined"

OtherfileSheet1VbNm.Select

How do inform my code that this named sheet exists in the workbook I have
jsut opened?

Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default How do you extract the VB name for a sheet in another file?

did you try

Activeworkbook.TemplateVbNm.activate

Tim



"ExcelMonkey" wrote in message
...
When I try to run the doe I get an error on the line:

TemplateVbNm.Select

This error occurs before the code even runs. You can see that I do
attempt
to activate the file first but since the error ocurrs before the
code runs,
the activate Method never gets a change to trigger. You can also
see the
line of code above the failed line is commented out. This line has
the
actuall sheet name in it. However I do not want to use this name as
the user
may want to change it.

Windows(ExtractedFileName).Activate
'Worksheets("Template").Select
TemplateVbNm.Select

Thanks

"quartz" wrote:

Usually the workbook you just opened will be active. In that case,

ActiveWorkbook.Sheets("OtherSheetName").Range("wha tever").select

If you need to activate it first then:

Workbooks("Workbook2").Activate
ActiveWorkbook.Sheets("YourSheetName").Range("what ever").Select

HTH.

"ExcelMonkey" wrote:

I know I can name sheets in the proptery window under the Name
property.

So if i write a macro in Worbook1 refering to a sheet in
Workbook1 that I
named "ThisfileSheet1VbNm I can say:

ThisfileSheet1VbNm.Range("A1").Select

But how do I refer to the name of a sheet in another workbook
(workbook2),
within my code in workbook 1. If I have a sheet named
"OtherfileSheet1VbNm"
in workbook 2, and I want to - upon opening workbook2 within
macro in
workbook1- select this sheet the following code gives me an
error: "Variable
not Defined"

OtherfileSheet1VbNm.Select

How do inform my code that this named sheet exists in the
workbook I have
jsut opened?

Thanks



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How do you extract the VB name for a sheet in another file?

One way:


Sub ABCD()
Dim bk As Workbook
Dim sh As Worksheet
Set bk = Workbooks.Open("C:\Data6\Workbook2.xls")
sName = bk.VBProject.VBComponents( _
"OtherfileSheet1VbNm").Properties("Name")
Set sh = bk.Worksheets(sName)
sh.Activate

End Sub


--
Regards,
Tom Ogilvy

"ExcelMonkey" wrote in message
...
I know I can name sheets in the proptery window under the Name property.

So if i write a macro in Worbook1 refering to a sheet in Workbook1 that I
named "ThisfileSheet1VbNm I can say:

ThisfileSheet1VbNm.Range("A1").Select

But how do I refer to the name of a sheet in another workbook (workbook2),
within my code in workbook 1. If I have a sheet named

"OtherfileSheet1VbNm"
in workbook 2, and I want to - upon opening workbook2 within macro in
workbook1- select this sheet the following code gives me an error:

"Variable
not Defined"

OtherfileSheet1VbNm.Select

How do inform my code that this named sheet exists in the workbook I have
jsut opened?

Thanks





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
Extract from one sheet to another Bcosta Excel Discussion (Misc queries) 5 July 7th 09 09:51 PM
How to extract a sheet from another? deedee Excel Discussion (Misc queries) 0 March 18th 09 10:26 PM
how to extract a sheet from another? deedee Excel Discussion (Misc queries) 2 March 18th 09 03:12 AM
Help me, compare 2 sheet and extract the match data into the new sheet. sweetnet Excel Discussion (Misc queries) 1 February 22nd 06 07:49 PM
Best way to extract data on one sheet & populate it on another sheet?????? WebWizard97 Excel Programming 1 September 25th 03 08:50 PM


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