ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   cpearson VBE question (https://www.excelbanter.com/excel-programming/294287-re-cpearson-vbe-question.html)

Ron Dahl[_2_]

cpearson VBE question
 
I sort of found the answer to my questions. If I delete the line:
Worksheets("Estimating Constants").Cells(1, 8).value = 2
The program then works. Worksheets("Estimating Constants") is a valid
worksheet, but somehow the program crashes with that line in it.
Ron Dahl

"Ron Dahl" wrote in message
...
I believe that I have used all the code that I can find on Chip Pearson's
site, but I'm still having problems.
The following code should delete the code module in a worksheet called
"Estimate" and then add new code module from the text file.
Whenever I run it I get the error message that will hopefully show at the
bottom of this posting saying that Microsoft Excel has encountered a

problem
and must close
Can anyone tell me how to fix this?
Thanks in advance for any help.
Ron Dahl

Sub UpgradewksEstimateFromVersion1ToVersion2()
On Error Resume Next
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False
If GetCodeModuleExists("Estimate") = True Then
DeleteCodeModule ("Estimate") 'See below


ActiveWorkbook.VBProject.VBComponents(Worksheets(" Estimate").CodeName).CodeM
odule.AddFromFile
Filename:="\\ghpd.com\network\prog\est\wksEstimate Events.txt"
Else


ActiveWorkbook.VBProject.VBComponents(Worksheets(" Estimate").CodeName).CodeM
odule.AddFromFile
Filename:="\\ghpd.com\network\prog\est\wksEstimate Events.txt"
End If

ActiveWorkbook.Save
Worksheets("Estimating Constants").Cells(1, 8).value = 2

Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

Sub DeleteCodeModule(ByVal sname As String)
Dim VBCodeMod As CodeModule
Dim StartLine As Long
Dim HowManyLines As Long

Set VBCodeMod =
ThisWorkbook.VBProject.VBComponents(Worksheets(sna me).CodeName).CodeModule
With VBCodeMod
StartLine = 1
HowManyLines = .CountOfLines
.DeleteLines StartLine, HowManyLines
End With
End Sub











All times are GMT +1. The time now is 02:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com