B
Bob White
Create a new workbook, then start VB and paste the following code into a
new code module. Close VB. Run the macro from Excel. The macro runs
correctly, yet VB reopens. Is there a way to either keep VB from opening
or a programmatic way to close it after it does?
Thanks for the help!
Bob
_____________________________________________________
Sub test()
Dim SheetName As String
SheetName = "XYZZY"
Set WS = ActiveWorkbook.Sheets.Add
WS.Name = SheetName
'
For i = 1 To ThisWorkbook.VBProject.VBComponents.Count
Set c = ThisWorkbook.VBProject.VBComponents(i)
If c.Type = 100 Then 'vbext_ct_document =100
If c.Properties("Name") = SheetName Then
ThisWorkbook.VBProject.VBComponents(i).Properties("_CodeName") = SheetName
End If
Next i
Set c = Nothing
'
With ActiveWorkbook.VBProject.VBComponents(SheetName).CodeModule
StartLine = .CreateEventProc("Change", "WorkSheet") + 1
.InsertLines StartLine, "Call OnPTSelectionChange"
End With
End Sub
new code module. Close VB. Run the macro from Excel. The macro runs
correctly, yet VB reopens. Is there a way to either keep VB from opening
or a programmatic way to close it after it does?
Thanks for the help!
Bob
_____________________________________________________
Sub test()
Dim SheetName As String
SheetName = "XYZZY"
Set WS = ActiveWorkbook.Sheets.Add
WS.Name = SheetName
'
For i = 1 To ThisWorkbook.VBProject.VBComponents.Count
Set c = ThisWorkbook.VBProject.VBComponents(i)
If c.Type = 100 Then 'vbext_ct_document =100
If c.Properties("Name") = SheetName Then
ThisWorkbook.VBProject.VBComponents(i).Properties("_CodeName") = SheetName
End If
Next i
Set c = Nothing
'
With ActiveWorkbook.VBProject.VBComponents(SheetName).CodeModule
StartLine = .CreateEventProc("Change", "WorkSheet") + 1
.InsertLines StartLine, "Call OnPTSelectionChange"
End With
End Sub