Accessing VBProject causes the program to crash

K

Klaus

I have a module that writes code to a worksheet..
I have checked "Trust access to Visual Basic Project.
Excel crashes.
Any ideas.


----------------------------------------------------------------------------------------------
Sub MoveCode()
'It produces event actions delete Save As and restore Save As code in
"ThisWorkbook" module
'It copies from file module_code, into Module1 the code for the help
file and delete Save As and restore Save As

FName = FilePath & "module_code.txt"
Set CurrentWorkbook = Workbooks(NewTimesheet)
CurrentWorkbook.VBProject.VBComponents.Import FName
Set VBCodeMod =
Workbooks(NewTimesheet).VBProject.VBComponents("ThisWorkbook").CodeModule
With VBCodeMod
LineNum = .CountOfLines + 1
.InsertLines LineNum, "Private Sub Workbook_Activate()" & Chr(13) &
" Delete_SaveAs" & Chr(13) & "End Sub"
.InsertLines LineNum, "Private Sub Workbook_Deactivate()" & Chr(13)
& " Restore_SaveAs" & Chr(13) & "End Sub"
End With

End Sub
--------------------------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top