PC Review


Reply
Thread Tools Rate Thread

Is it a BUG or am I missing something?

 
 
=?Utf-8?B?S1QxOTcy?=
Guest
Posts: n/a
 
      18th Mar 2007
Could you try the following case?

Lets create an excel workbook name is dummy1.xls including the code:
Private Sub Workbook_Deactivate()
MsgBox "deactivate"
End Sub
Private Sub Workbook_Open()
MsgBox "OLD message"
End Sub

And another workbook (dummy2.xls) to change dummy1 subs:
Sub ChangeMacros()
Dim vbc As VBComponent, i As Long, j As Long, strProcName As String, strTemp
As String
Dim strMacroList As String
Dim File
'On Error Resume Next
File = "c:\dummy1.xls"
Workbooks.Open Filename:=File, UpdateLinks:=0, ReadOnly:=False
strMacroList = ""
For Each vbc In ActiveWorkbook.VBProject.VBComponents
If vbc.Type = vbext_ct_Document Or vbc.Type = vbext_ct_StdModule Then
With vbc.CodeModule
If vbc.CodeModule = "ThisWorkbook" Then
i = .CountOfLines
If i <> 0 Then
.DeleteLines 1, i
End If
.InsertLines 100, _
"Private Sub Workbook_Open()" & Chr(13) & _
"msgbox ""NEW message""" & Chr(13) & _
"End Sub" & Chr(13)
End If
End With
End If
Next
ActiveWorkbook.Close True
End Sub

When I run ChangeMacros, excel is crashing. If I manually remove one of the
subs (open or deactivate) from dummy1 and try to run ChangeMacros" sub in
dummy2, it is running without any problem.

Thanks


 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      18th Mar 2007
Try disabling events before opening dummy1.xls. Consider also assigning
dummy1.xls to a workbook variable instead of just using the Activeworkbook
object.

Sub ChangeMacros()
Dim vbc As VBComponent, i As Long, j As Long, strProcName As String,
strTemp As String
Dim strMacroList As String
Dim File
Dim wb As Workbook
'On Error Resume Next
File = "c:\dummy1.xls"
Application.EnableEvents = False
Set wb = Workbooks.Open(Filename:=File, UpdateLinks:=0, ReadOnly:=False)
strMacroList = ""
For Each vbc In wb.VBProject.VBComponents
If vbc.Type = vbext_ct_Document Or vbc.Type = vbext_ct_StdModule Then
With vbc.CodeModule
If vbc.CodeModule = "ThisWorkbook" Then
i = .CountOfLines
If i < 0 Then
.DeleteLines 1, i
End If
.InsertLines 100, _
"Private Sub Workbook_Open()" & Chr(13) & _
"msgbox ""NEW message""" & Chr(13) & _
"End Sub" & Chr(13)
End If
End With
End If
Next
wb.Close True
Application.EnableEvents = True
End Sub



"KT1972" wrote:

> Could you try the following case?
>
> Lets create an excel workbook name is dummy1.xls including the code:
> Private Sub Workbook_Deactivate()
> MsgBox "deactivate"
> End Sub
> Private Sub Workbook_Open()
> MsgBox "OLD message"
> End Sub
>
> And another workbook (dummy2.xls) to change dummy1 subs:
> Sub ChangeMacros()
> Dim vbc As VBComponent, i As Long, j As Long, strProcName As String, strTemp
> As String
> Dim strMacroList As String
> Dim File
> 'On Error Resume Next
> File = "c:\dummy1.xls"
> Workbooks.Open Filename:=File, UpdateLinks:=0, ReadOnly:=False
> strMacroList = ""
> For Each vbc In ActiveWorkbook.VBProject.VBComponents
> If vbc.Type = vbext_ct_Document Or vbc.Type = vbext_ct_StdModule Then
> With vbc.CodeModule
> If vbc.CodeModule = "ThisWorkbook" Then
> i = .CountOfLines
> If i <> 0 Then
> .DeleteLines 1, i
> End If
> .InsertLines 100, _
> "Private Sub Workbook_Open()" & Chr(13) & _
> "msgbox ""NEW message""" & Chr(13) & _
> "End Sub" & Chr(13)
> End If
> End With
> End If
> Next
> ActiveWorkbook.Close True
> End Sub
>
> When I run ChangeMacros, excel is crashing. If I manually remove one of the
> subs (open or deactivate) from dummy1 and try to run ChangeMacros" sub in
> dummy2, it is running without any problem.
>
> Thanks
>
>

 
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
Crystal Reports - Visual Basic UFL that implements this function is missing (or U2lcom.dll is missing) Les Caudle Microsoft ASP .NET 3 3rd Sep 2007 03:27 AM
Missing Tasbar, Missing Start Button, Missing Desktop Icons =?Utf-8?B?TWlrZSBGaXNoZXI=?= Windows XP General 1 27th Dec 2005 09:03 PM
On Error? Creates 1 missing worksheet then never detects any other missing worksheets Craigm Microsoft Excel Programming 2 1st Aug 2005 02:39 PM
can't boot up -- system file missing -- INF txtsetup.sif missing on bootdisks jen katz Windows XP Performance 0 27th Dec 2003 12:34 AM
Correct missing fixed font, missing registry data Mark Kraft Windows XP Embedded 2 9th Jul 2003 05:31 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:43 PM.