View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Nick Dreyer Nick Dreyer is offline
external usenet poster
 
Posts: 10
Default Changing VBE WS-component name in code craches excel 97

Changing the VBE component name of any worksheet, as illustrated
in the sample code below predictably crashes my installation of excel
97.
I can do it manually without a problem, but . . .

Anyboy seen something like this before? If not try it . . . this looks
like an MS bug to me.
I'm running on Windows XP Professional Version 5.1 (Build
2600.xpsp2.050301-1526: Service Pack 1)
523 MB Ram

(Of course you have to add a reference to: "Microsoft Visual Basic for
Applications Extensibility")
________________________________________________

Sub MakeACorruptWorkbook()
'
' Warning: Run it and you *will* crash this excel 97 session !!!
'
Dim WSname As String
Workbooks.Add
ComponentofWS(ActiveWorkbook.Worksheets(1)).Name = "Sheet2"
Application.DisplayAlerts = False
ActiveWorkbook.Save
Application.DisplayAlerts = True
WSname = ActiveWorkbook.FullName
ActiveWorkbook.Close
Workbooks.Open FileName:=WSname ' What bomb just went off ???
End Sub

Function ComponentofWS(ws As Worksheet) As VBComponent
Dim ThisProperty As Property
Dim SourceComponent As VBComponent
Dim SourceComponents As VBComponents
Set SourceComponents = ws.Parent.VBProject.VBComponents
For Each SourceComponent In SourceComponents
If SourceComponent.Type = vbext_ct_Document Then
For Each ThisProperty In SourceComponent.Properties
If ThisProperty.Name = "Name" Then
If ThisProperty.Value = ws.Name Then
Set ComponentofWS = SourceComponent
Exit Function
End If
End If
Next
End If
Next
End Function