realniceguy5000
Board Regular
- Joined
- Aug 19, 2008
- Messages
- 148
Hi Everyone,
I have cross posted to get more ideas of why this is happening...
I thought I had this fixed late yesterday, But the same problem happened again this morning. This all generated from this post
The code below resides in my personal.XLS Module. When I step through the code everything works till it reaches the point in red then I get the pop up that says excel needs to close and asks to send or not to send.
I noticed that if I choose recover my work and restart excel and I look at the code in THISWORKBOOK of the recovered workbook that the code I wanted was placed in there.
Can anyone explain why this is happening? I have the macro's security set to low and a check mark in the trust access to vb projects.
Any Idea's how to fix this?
Thank You
Mike
I have cross posted to get more ideas of why this is happening...
Code:
[URL]http://www.excelforum.com/excel-programming/679287-excel-crashes-when-adding-code-to-workbook-via-vba.html[/URL]
I thought I had this fixed late yesterday, But the same problem happened again this morning. This all generated from this post
Code:
[URL]http://www.excelforum.com/excel-programming/678982-insert-code-into-this-workbook-mod.html#post2073179[/URL]
I noticed that if I choose recover my work and restart excel and I look at the code in THISWORKBOOK of the recovered workbook that the code I wanted was placed in there.
Can anyone explain why this is happening? I have the macro's security set to low and a check mark in the trust access to vb projects.
Any Idea's how to fix this?
Thank You
Mike
Code:
Sub OpenALL() 'open workbooks in a folder
Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
On Error Resume Next
Set wbCodeBook = ThisWorkbook
With Application.FileSearch
.NewSearch
.LookIn = "G:\Hazleton Production\2009 Production\Production Links\2009 Varsity"
.FileType = msoFileTypeExcelWorkbooks
If .Execute > 0 Then
For lCount = 1 To .FoundFiles.Count 'Loop through all.
Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
ActiveSheet.unProtect "password"
AddCodeToThisWorkbook ActiveWorkbook, "C:\Documents and Settings\MAlston\Desktop\Count Sheets\mycode.txt"
wbResults.Close SaveChanges:=True
Next lCount
End If
End With
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
Code:
Sub AddCodeToThisWorkbook(wkb As Workbook, sFile As String, _
Optional bReplace As Boolean = False)
With wkb.VBProject.VBComponents(wkb.CodeName).CodeModule
If bReplace Then .DeleteLines StartLine:=1, Count:=.CountOfLines
[COLOR=red].AddFromFile sFile[/COLOR]
End With
End Sub