Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Hondo Chalthoum    on Jan 31 In MS Office Category.

  
Question Answered By: Eula Armstrong   on Jan 31

I got it to run, but have the following Questions about the code.
Here's my whole Sub:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub ListNamedCells()
' Show Range Names.
Dim R As Integer
Dim WBName As String
Dim defined_name As Object ' Error said must be Object or Variant

Workbooks.Add
WBName = ActiveWorkbook.Name
' Workbooks(WBName).Save
Cells(1, 5).Value = ThisWorkbook.Names.Count ' I added this
R = 1
For Each defined_name In ThisWorkbook.Names
Cells(R, 1).Value = R ' Show the: Item number
Cells(R, 2).Value = defined_name ' Range Address
Cells(R, 3).Value = defined_name.Name ' Range Name
R = R + 1
Next
End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Errors told me I needed the Dim's... However.

1 - How does VBA know that "defined_name" contains the name? I don't
see where it gets assigned [defined_name = ??]. Is it just because
the "For Each" construct needs a place to hold the members of the
collection "ThisWorkbook.Names", so it puts them there?

2 - What is the purpose of the line:
Workbooks(WBName).Save
Works fine without it.

3 - With these two statements:
Workbooks.Add
WBName = ActiveWorkbook.Name

I have Active workbook  Object confusion.
Why isn't the added workbook the active one - Is it because adding
a workbook doesn't make it active?
If the added one is not the active one, why do the Names get stored
there? There is no explicit workbook or sheet specified "Cells(...".

Share: 

 

This Question has 8 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Listing named cells Or get search suggestion and latest updates.


Tagged: