PC Review


Reply
Thread Tools Rate Thread

Chapter 5 professional Excel Development

 
 
=?Utf-8?B?bHVtcHVz?=
Guest
Posts: n/a
 
      21st Sep 2007
I have two questions from chapter 5 of "profession excel development"

I am fairly new to vba so forgive me if these are dumb questions

1st
what exactly does this mean (more specifically the part starting with
rngName.Value, "=" & rngSetting.Value)

wksSheet.Names.Add rngName.Value, _
"=" & rngSetting.Value
(see code below)

2nd
can someone explain to me step by step what the Private Function

sSheetTabName(ByRef wkbProject As Workbook, _
ByRef sCodeName As String) As String
does and how it works.

(see bottom of the page)

Option Explicit
Option Private Module


Private Const msFILE_TIME_ENTRY As String = "PetrasTemplate.xls"
Private Const msRNG_NAME_LIST As String = "tblRangeNames"
Private Const msRNG_SHEET_LIST As String = "tblSheetNames"

' 03/15/04 Rob Bovey Ch05 Initial version
'
Public Sub WriteSettings()

Dim rngSheet As Range
Dim rngSheetList As Range
Dim rngName As Range
Dim rngNameList As Range
Dim rngSetting As Range
Dim sSheetTab As String
Dim wkbBook As Workbook
Dim wksSheet As Worksheet




Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Set wkbBook = Application.Workbooks(msFILE_TIME_ENTRY)
' The list of worksheets in the first column.
Set rngSheetList = wksUISettings.Range(msRNG_SHEET_LIST)
' The list of setting names in the first row.
Set rngNameList = wksUISettings.Range(msRNG_NAME_LIST)

' The outer loop processes all the worksheets in the
' first column of the table.
For Each rngSheet In rngSheetList

' We need an object reference to the worksheet so we
' can easily add a sheet-level defined name to it.
' The sSheetTabName() function converts a CodeName
' into its corresponding sheet tab name.
sSheetTab = sSheetTabName(wkbBook, rngSheet.Value)
Set wksSheet = wkbBook.Worksheets(sSheetTab)

' The inner loop adds each setting to the current sheet.
' If the setting already exists it will be replaced.
For Each rngName In rngNameList

' The value of the setting is contained in the cell
' where the worksheet row and range name column
' intersect.
Set rngSetting = Intersect(rngSheet.EntireRow, _
rngName.EntireColumn)


' We only create defined names for settings that
' have been given a non-zero-length value.

If Len(rngSetting.Value) > 0 Then
wksSheet.Names.Add rngName.Value, _
"=" & rngSetting.Value

End If

Next rngName

Next rngSheet

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub

Private Function sSheetTabName(ByRef wkbProject As Workbook, _
ByRef sCodeName As String) As String

Dim wksSheet As Worksheet
For Each wksSheet In wkbProject.Worksheets
If wksSheet.CodeName = sCodeName Then 'sCodeName is paremeter in
argument
sSheetTabName = wksSheet.Name
Exit For
End If
Next wksSheet
End Function




 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      21st Sep 2007
Homework?

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"lumpus" <(E-Mail Removed)> wrote in message
news:606EC44A-D59D-41C8-857B-(E-Mail Removed)...
>I have two questions from chapter 5 of "profession excel development"
>
> I am fairly new to vba so forgive me if these are dumb questions
>
> 1st
> what exactly does this mean (more specifically the part starting with
> rngName.Value, "=" & rngSetting.Value)
>
> wksSheet.Names.Add rngName.Value, _
> "=" & rngSetting.Value
> (see code below)
>
> 2nd
> can someone explain to me step by step what the Private Function
>
> sSheetTabName(ByRef wkbProject As Workbook, _
> ByRef sCodeName As String) As String
> does and how it works.
>
> (see bottom of the page)
>
> Option Explicit
> Option Private Module
>
>
> Private Const msFILE_TIME_ENTRY As String = "PetrasTemplate.xls"
> Private Const msRNG_NAME_LIST As String = "tblRangeNames"
> Private Const msRNG_SHEET_LIST As String = "tblSheetNames"
>
> ' 03/15/04 Rob Bovey Ch05 Initial version
> '
> Public Sub WriteSettings()
>
> Dim rngSheet As Range
> Dim rngSheetList As Range
> Dim rngName As Range
> Dim rngNameList As Range
> Dim rngSetting As Range
> Dim sSheetTab As String
> Dim wkbBook As Workbook
> Dim wksSheet As Worksheet
>
>
>
>
> Application.ScreenUpdating = False
> Application.Calculation = xlCalculationManual
>
> Set wkbBook = Application.Workbooks(msFILE_TIME_ENTRY)
> ' The list of worksheets in the first column.
> Set rngSheetList = wksUISettings.Range(msRNG_SHEET_LIST)
> ' The list of setting names in the first row.
> Set rngNameList = wksUISettings.Range(msRNG_NAME_LIST)
>
> ' The outer loop processes all the worksheets in the
> ' first column of the table.
> For Each rngSheet In rngSheetList
>
> ' We need an object reference to the worksheet so we
> ' can easily add a sheet-level defined name to it.
> ' The sSheetTabName() function converts a CodeName
> ' into its corresponding sheet tab name.
> sSheetTab = sSheetTabName(wkbBook, rngSheet.Value)
> Set wksSheet = wkbBook.Worksheets(sSheetTab)
>
> ' The inner loop adds each setting to the current sheet.
> ' If the setting already exists it will be replaced.
> For Each rngName In rngNameList
>
> ' The value of the setting is contained in the cell
> ' where the worksheet row and range name column
> ' intersect.
> Set rngSetting = Intersect(rngSheet.EntireRow, _
> rngName.EntireColumn)
>
>
> ' We only create defined names for settings that
> ' have been given a non-zero-length value.
>
> If Len(rngSetting.Value) > 0 Then
> wksSheet.Names.Add rngName.Value, _
> "=" & rngSetting.Value
>
> End If
>
> Next rngName
>
> Next rngSheet
>
> Application.ScreenUpdating = True
> Application.Calculation = xlCalculationAutomatic
>
> End Sub
>
> Private Function sSheetTabName(ByRef wkbProject As Workbook, _
> ByRef sCodeName As String) As String
>
> Dim wksSheet As Worksheet
> For Each wksSheet In wkbProject.Worksheets
> If wksSheet.CodeName = sCodeName Then 'sCodeName is paremeter in
> argument
> sSheetTabName = wksSheet.Name
> Exit For
> End If
> Next wksSheet
> End Function
>
>
>
>


 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      21st Sep 2007
1st

It is adding a defined name and calling it by the value in rngName, and
giving it a RefersTo value of the value in rngSetting

2nd

his function returns the Excel sheet name when the sheets codename is known.

The workbook object and the coiodename is passed as parameters.

A loop is setup to iterate through all worksheets in the target workbook
If the current sheet's coden ame is the same as the codename passed as the
parameter, then the Excel sheet name is extracted, and the loope is exited
The found value is returned.

Private Function sSheetTabName(ByRef wkbProject As Workbook, _
ByRef sCodeName As String) As String

Dim wksSheet As Worksheet
For Each wksSheet In wkbProject.Worksheets
If wksSheet.CodeName = sCodeName Then 'sCodeName is paremeter in argument
sSheetTabName = wksSheet.Name
Exit For
End If
Next wksSheet
End Function

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"lumpus" <(E-Mail Removed)> wrote in message
news:606EC44A-D59D-41C8-857B-(E-Mail Removed)...
>I have two questions from chapter 5 of "profession excel development"
>
> I am fairly new to vba so forgive me if these are dumb questions
>
> 1st
> what exactly does this mean (more specifically the part starting with
> rngName.Value, "=" & rngSetting.Value)
>
> wksSheet.Names.Add rngName.Value, _
> "=" & rngSetting.Value
> (see code below)
>
> 2nd
> can someone explain to me step by step what the Private Function
>
> sSheetTabName(ByRef wkbProject As Workbook, _
> ByRef sCodeName As String) As String
> does and how it works.
>
> (see bottom of the page)
>
> Option Explicit
> Option Private Module
>
>
> Private Const msFILE_TIME_ENTRY As String = "PetrasTemplate.xls"
> Private Const msRNG_NAME_LIST As String = "tblRangeNames"
> Private Const msRNG_SHEET_LIST As String = "tblSheetNames"
>
> ' 03/15/04 Rob Bovey Ch05 Initial version
> '
> Public Sub WriteSettings()
>
> Dim rngSheet As Range
> Dim rngSheetList As Range
> Dim rngName As Range
> Dim rngNameList As Range
> Dim rngSetting As Range
> Dim sSheetTab As String
> Dim wkbBook As Workbook
> Dim wksSheet As Worksheet
>
>
>
>
> Application.ScreenUpdating = False
> Application.Calculation = xlCalculationManual
>
> Set wkbBook = Application.Workbooks(msFILE_TIME_ENTRY)
> ' The list of worksheets in the first column.
> Set rngSheetList = wksUISettings.Range(msRNG_SHEET_LIST)
> ' The list of setting names in the first row.
> Set rngNameList = wksUISettings.Range(msRNG_NAME_LIST)
>
> ' The outer loop processes all the worksheets in the
> ' first column of the table.
> For Each rngSheet In rngSheetList
>
> ' We need an object reference to the worksheet so we
> ' can easily add a sheet-level defined name to it.
> ' The sSheetTabName() function converts a CodeName
> ' into its corresponding sheet tab name.
> sSheetTab = sSheetTabName(wkbBook, rngSheet.Value)
> Set wksSheet = wkbBook.Worksheets(sSheetTab)
>
> ' The inner loop adds each setting to the current sheet.
> ' If the setting already exists it will be replaced.
> For Each rngName In rngNameList
>
> ' The value of the setting is contained in the cell
> ' where the worksheet row and range name column
> ' intersect.
> Set rngSetting = Intersect(rngSheet.EntireRow, _
> rngName.EntireColumn)
>
>
> ' We only create defined names for settings that
> ' have been given a non-zero-length value.
>
> If Len(rngSetting.Value) > 0 Then
> wksSheet.Names.Add rngName.Value, _
> "=" & rngSetting.Value
>
> End If
>
> Next rngName
>
> Next rngSheet
>
> Application.ScreenUpdating = True
> Application.Calculation = xlCalculationAutomatic
>
> End Sub
>
> Private Function sSheetTabName(ByRef wkbProject As Workbook, _
> ByRef sCodeName As String) As String
>
> Dim wksSheet As Worksheet
> For Each wksSheet In wkbProject.Worksheets
> If wksSheet.CodeName = sCodeName Then 'sCodeName is paremeter in
> argument
> sSheetTabName = wksSheet.Name
> Exit For
> End If
> Next wksSheet
> End Function
>
>
>
>



 
Reply With Quote
 
=?Utf-8?B?bHVtcHVz?=
Guest
Posts: n/a
 
      22nd Sep 2007

Thanks for the help.

BTW it is not homework just teaching myself vba it useful for
my job.


"Bob Phillips" wrote:

> 1st
>
> It is adding a defined name and calling it by the value in rngName, and
> giving it a RefersTo value of the value in rngSetting
>
> 2nd
>
> his function returns the Excel sheet name when the sheets codename is known.
>
> The workbook object and the coiodename is passed as parameters.
>
> A loop is setup to iterate through all worksheets in the target workbook
> If the current sheet's coden ame is the same as the codename passed as the
> parameter, then the Excel sheet name is extracted, and the loope is exited
> The found value is returned.
>
> Private Function sSheetTabName(ByRef wkbProject As Workbook, _
> ByRef sCodeName As String) As String
>
> Dim wksSheet As Worksheet
> For Each wksSheet In wkbProject.Worksheets
> If wksSheet.CodeName = sCodeName Then 'sCodeName is paremeter in argument
> sSheetTabName = wksSheet.Name
> Exit For
> End If
> Next wksSheet
> End Function
>
> --
> ---
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
>
>
> "lumpus" <(E-Mail Removed)> wrote in message
> news:606EC44A-D59D-41C8-857B-(E-Mail Removed)...
> >I have two questions from chapter 5 of "profession excel development"
> >
> > I am fairly new to vba so forgive me if these are dumb questions
> >
> > 1st
> > what exactly does this mean (more specifically the part starting with
> > rngName.Value, "=" & rngSetting.Value)
> >
> > wksSheet.Names.Add rngName.Value, _
> > "=" & rngSetting.Value
> > (see code below)
> >
> > 2nd
> > can someone explain to me step by step what the Private Function
> >
> > sSheetTabName(ByRef wkbProject As Workbook, _
> > ByRef sCodeName As String) As String
> > does and how it works.
> >
> > (see bottom of the page)
> >
> > Option Explicit
> > Option Private Module
> >
> >
> > Private Const msFILE_TIME_ENTRY As String = "PetrasTemplate.xls"
> > Private Const msRNG_NAME_LIST As String = "tblRangeNames"
> > Private Const msRNG_SHEET_LIST As String = "tblSheetNames"
> >
> > ' 03/15/04 Rob Bovey Ch05 Initial version
> > '
> > Public Sub WriteSettings()
> >
> > Dim rngSheet As Range
> > Dim rngSheetList As Range
> > Dim rngName As Range
> > Dim rngNameList As Range
> > Dim rngSetting As Range
> > Dim sSheetTab As String
> > Dim wkbBook As Workbook
> > Dim wksSheet As Worksheet
> >
> >
> >
> >
> > Application.ScreenUpdating = False
> > Application.Calculation = xlCalculationManual
> >
> > Set wkbBook = Application.Workbooks(msFILE_TIME_ENTRY)
> > ' The list of worksheets in the first column.
> > Set rngSheetList = wksUISettings.Range(msRNG_SHEET_LIST)
> > ' The list of setting names in the first row.
> > Set rngNameList = wksUISettings.Range(msRNG_NAME_LIST)
> >
> > ' The outer loop processes all the worksheets in the
> > ' first column of the table.
> > For Each rngSheet In rngSheetList
> >
> > ' We need an object reference to the worksheet so we
> > ' can easily add a sheet-level defined name to it.
> > ' The sSheetTabName() function converts a CodeName
> > ' into its corresponding sheet tab name.
> > sSheetTab = sSheetTabName(wkbBook, rngSheet.Value)
> > Set wksSheet = wkbBook.Worksheets(sSheetTab)
> >
> > ' The inner loop adds each setting to the current sheet.
> > ' If the setting already exists it will be replaced.
> > For Each rngName In rngNameList
> >
> > ' The value of the setting is contained in the cell
> > ' where the worksheet row and range name column
> > ' intersect.
> > Set rngSetting = Intersect(rngSheet.EntireRow, _
> > rngName.EntireColumn)
> >
> >
> > ' We only create defined names for settings that
> > ' have been given a non-zero-length value.
> >
> > If Len(rngSetting.Value) > 0 Then
> > wksSheet.Names.Add rngName.Value, _
> > "=" & rngSetting.Value
> >
> > End If
> >
> > Next rngName
> >
> > Next rngSheet
> >
> > Application.ScreenUpdating = True
> > Application.Calculation = xlCalculationAutomatic
> >
> > End Sub
> >
> > Private Function sSheetTabName(ByRef wkbProject As Workbook, _
> > ByRef sCodeName As String) As String
> >
> > Dim wksSheet As Worksheet
> > For Each wksSheet In wkbProject.Worksheets
> > If wksSheet.CodeName = sCodeName Then 'sCodeName is paremeter in
> > argument
> > sSheetTabName = wksSheet.Name
> > Exit For
> > End If
> > Next wksSheet
> > End Function
> >
> >
> >
> >

>
>
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      22nd Sep 2007
I never said it was. I must say that it seemed unlikely, homework usually
applies at a much more basic level than that particular tome :-)

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"lumpus" <(E-Mail Removed)> wrote in message
newsB473A49-4B63-48C9-BB24-(E-Mail Removed)...
>
> Thanks for the help.
>
> BTW it is not homework just teaching myself vba it useful for
> my job.
>
>
> "Bob Phillips" wrote:
>
>> 1st
>>
>> It is adding a defined name and calling it by the value in rngName, and
>> giving it a RefersTo value of the value in rngSetting
>>
>> 2nd
>>
>> his function returns the Excel sheet name when the sheets codename is
>> known.
>>
>> The workbook object and the coiodename is passed as parameters.
>>
>> A loop is setup to iterate through all worksheets in the target workbook
>> If the current sheet's coden ame is the same as the codename passed as
>> the
>> parameter, then the Excel sheet name is extracted, and the loope is
>> exited
>> The found value is returned.
>>
>> Private Function sSheetTabName(ByRef wkbProject As Workbook, _
>> ByRef sCodeName As String) As String
>>
>> Dim wksSheet As Worksheet
>> For Each wksSheet In wkbProject.Worksheets
>> If wksSheet.CodeName = sCodeName Then 'sCodeName is paremeter in argument
>> sSheetTabName = wksSheet.Name
>> Exit For
>> End If
>> Next wksSheet
>> End Function
>>
>> --
>> ---
>> HTH
>>
>> Bob
>>
>> (there's no email, no snail mail, but somewhere should be gmail in my
>> addy)
>>
>>
>>
>> "lumpus" <(E-Mail Removed)> wrote in message
>> news:606EC44A-D59D-41C8-857B-(E-Mail Removed)...
>> >I have two questions from chapter 5 of "profession excel development"
>> >
>> > I am fairly new to vba so forgive me if these are dumb questions
>> >
>> > 1st
>> > what exactly does this mean (more specifically the part starting with
>> > rngName.Value, "=" & rngSetting.Value)
>> >
>> > wksSheet.Names.Add rngName.Value, _
>> > "=" & rngSetting.Value
>> > (see code below)
>> >
>> > 2nd
>> > can someone explain to me step by step what the Private Function
>> >
>> > sSheetTabName(ByRef wkbProject As Workbook, _
>> > ByRef sCodeName As String) As String
>> > does and how it works.
>> >
>> > (see bottom of the page)
>> >
>> > Option Explicit
>> > Option Private Module
>> >
>> >
>> > Private Const msFILE_TIME_ENTRY As String = "PetrasTemplate.xls"
>> > Private Const msRNG_NAME_LIST As String = "tblRangeNames"
>> > Private Const msRNG_SHEET_LIST As String = "tblSheetNames"
>> >
>> > ' 03/15/04 Rob Bovey Ch05 Initial version
>> > '
>> > Public Sub WriteSettings()
>> >
>> > Dim rngSheet As Range
>> > Dim rngSheetList As Range
>> > Dim rngName As Range
>> > Dim rngNameList As Range
>> > Dim rngSetting As Range
>> > Dim sSheetTab As String
>> > Dim wkbBook As Workbook
>> > Dim wksSheet As Worksheet
>> >
>> >
>> >
>> >
>> > Application.ScreenUpdating = False
>> > Application.Calculation = xlCalculationManual
>> >
>> > Set wkbBook = Application.Workbooks(msFILE_TIME_ENTRY)
>> > ' The list of worksheets in the first column.
>> > Set rngSheetList = wksUISettings.Range(msRNG_SHEET_LIST)
>> > ' The list of setting names in the first row.
>> > Set rngNameList = wksUISettings.Range(msRNG_NAME_LIST)
>> >
>> > ' The outer loop processes all the worksheets in the
>> > ' first column of the table.
>> > For Each rngSheet In rngSheetList
>> >
>> > ' We need an object reference to the worksheet so we
>> > ' can easily add a sheet-level defined name to it.
>> > ' The sSheetTabName() function converts a CodeName
>> > ' into its corresponding sheet tab name.
>> > sSheetTab = sSheetTabName(wkbBook, rngSheet.Value)
>> > Set wksSheet = wkbBook.Worksheets(sSheetTab)
>> >
>> > ' The inner loop adds each setting to the current sheet.
>> > ' If the setting already exists it will be replaced.
>> > For Each rngName In rngNameList
>> >
>> > ' The value of the setting is contained in the cell
>> > ' where the worksheet row and range name column
>> > ' intersect.
>> > Set rngSetting = Intersect(rngSheet.EntireRow, _
>> > rngName.EntireColumn)
>> >
>> >
>> > ' We only create defined names for settings that
>> > ' have been given a non-zero-length value.
>> >
>> > If Len(rngSetting.Value) > 0 Then
>> > wksSheet.Names.Add rngName.Value, _
>> > "=" & rngSetting.Value
>> >
>> > End If
>> >
>> > Next rngName
>> >
>> > Next rngSheet
>> >
>> > Application.ScreenUpdating = True
>> > Application.Calculation = xlCalculationAutomatic
>> >
>> > End Sub
>> >
>> > Private Function sSheetTabName(ByRef wkbProject As Workbook, _
>> > ByRef sCodeName As String) As String
>> >
>> > Dim wksSheet As Worksheet
>> > For Each wksSheet In wkbProject.Worksheets
>> > If wksSheet.CodeName = sCodeName Then 'sCodeName is paremeter in
>> > argument
>> > sSheetTabName = wksSheet.Name
>> > Exit For
>> > End If
>> > Next wksSheet
>> > End Function
>> >
>> >
>> >
>> >

>>
>>
>>



 
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
Professional Excel Development Chapter 5 greg.bieber@gmail.com Microsoft Excel Programming 1 28th Sep 2007 07:04 PM
Word macro to extract chapter preserving chapter and page numbering don.hosek@gmail.com Microsoft Word Document Management 2 13th Jul 2007 10:07 PM
Professional Excel Development =?Utf-8?B?RS5RLg==?= Microsoft Excel Misc 1 17th Aug 2006 04:43 AM
Professional Excel Development book question Mark Driscol Microsoft Excel Programming 13 6th May 2006 06:25 PM
development tools for professional teams Brian Henry Microsoft VB .NET 4 23rd Mar 2005 11:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:51 PM.