ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Worksheet in VB COMPONENT (https://www.excelbanter.com/excel-programming/328896-worksheet-vbulletin-component.html)

al

Worksheet in VB COMPONENT
 
I'm using the following code to add an event procedure to a worksheets code.
Rather than having to refer to the worksheet
as "Sheet1", i would like to refer to the worksheet as its actual
name, which is 10. How could I do so? Thanks in advance. See
the following code where "SHEET1" is used.

Sub addactivate()
Dim StartLine As Long
With ActiveWorkbook.VBProject.VBComponents("SHEET1").Co deModule
StartLine = .CreateEventProc("Activate", "Worksheet") + 1
.InsertLines StartLine, _
"If lastAddress < """" Then Range(lastAddress).Select"
End With

End Sub


Bob Phillips[_7_]

Worksheet in VB COMPONENT
 
Do you mean

With
ActiveWorkbook.VBProject.VBComponents(Worksheets(" 10").CodeName).CodeModule

--
HTH

Bob Phillips

"Al" wrote in message
...
I'm using the following code to add an event procedure to a worksheets

code.
Rather than having to refer to the worksheet
as "Sheet1", i would like to refer to the worksheet as its actual
name, which is 10. How could I do so? Thanks in advance. See
the following code where "SHEET1" is used.

Sub addactivate()
Dim StartLine As Long
With ActiveWorkbook.VBProject.VBComponents("SHEET1").Co deModule
StartLine = .CreateEventProc("Activate", "Worksheet") + 1
.InsertLines StartLine, _
"If lastAddress < """" Then Range(lastAddress).Select"
End With

End Sub




Tom Ogilvy

Worksheet in VB COMPONENT
 
Sub addactivate()
Dim StartLine As Long
Dim s As String
s = ActiveworkBook.Worksheets("10").Codename
With ActiveWorkbook.VBProject.VBComponents(s).CodeModul e
StartLine = .CreateEventProc("Activate", "Worksheet") + 1
.InsertLines StartLine, _
"If lastAddress < """" Then Range(lastAddress).Select"
End With

End Sub

--
Regrds,
Tom Ogilvy



"Al" wrote in message
...
I'm using the following code to add an event procedure to a worksheets

code.
Rather than having to refer to the worksheet
as "Sheet1", i would like to refer to the worksheet as its actual
name, which is 10. How could I do so? Thanks in advance. See
the following code where "SHEET1" is used.

Sub addactivate()
Dim StartLine As Long
With ActiveWorkbook.VBProject.VBComponents("SHEET1").Co deModule
StartLine = .CreateEventProc("Activate", "Worksheet") + 1
.InsertLines StartLine, _
"If lastAddress < """" Then Range(lastAddress).Select"
End With

End Sub




al

Worksheet in VB COMPONENT
 
Thanks Bob and Tom!!

"Bob Phillips" wrote:

Do you mean

With
ActiveWorkbook.VBProject.VBComponents(Worksheets(" 10").CodeName).CodeModule

--
HTH

Bob Phillips

"Al" wrote in message
...
I'm using the following code to add an event procedure to a worksheets

code.
Rather than having to refer to the worksheet
as "Sheet1", i would like to refer to the worksheet as its actual
name, which is 10. How could I do so? Thanks in advance. See
the following code where "SHEET1" is used.

Sub addactivate()
Dim StartLine As Long
With ActiveWorkbook.VBProject.VBComponents("SHEET1").Co deModule
StartLine = .CreateEventProc("Activate", "Worksheet") + 1
.InsertLines StartLine, _
"If lastAddress < """" Then Range(lastAddress).Select"
End With

End Sub






All times are GMT +1. The time now is 01:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com