R
Resant
Hi all, I have a problem.
I try to replace a procedure (named Dynamic_Macro) at run-time, by
delete the procedure and then add it again using VBE. That's work
succesfully...
But when I try to execute that new procedure, the Excel always close
and restart again. I have add timer between create the procedure and
execute process, but still cause Excel restart. I'm sure nothing wrong
with the new procedure, 'cause when I separate the executing coding,
it's executed succesfully.
My coding is :
Dim VBCodeMod As CodeModule
Dim StartLine As Long
Dim HowManyLines As Long
Dim LineNum As Long
strScript = ""
Set VBCodeMod =
ThisWorkbook.VBProject.VBComponents("Module2").CodeModule
With VBCodeMod
'Delete proc Dynamic_Macro
StartLine = .ProcStartLine("Dynamic_Macro", vbext_pk_Proc)
HowManyLines = .ProcCountLines("Dynamic_Macro",
vbext_pk_Proc)
.DeleteLines StartLine, HowManyLines
'Add again proc Dynamic_Macro
strScript = ""
ReadText "Macro.txt", strScript
LineNum = .CountOfLines + 1
.InsertLines LineNum, strScript
Application.Wait (Now() + TimeValue("0:00:50"))
Application.Run "Dynamic_Macro"
End With
ReadText is a procedure that read Dynamic_Macro content from a file
text "Macro.txt" and pasing to strScript variable.
Please would should I do in order to I can excute it immediately after
created in one procedure?
Thanks for your help,
Resant
I try to replace a procedure (named Dynamic_Macro) at run-time, by
delete the procedure and then add it again using VBE. That's work
succesfully...
But when I try to execute that new procedure, the Excel always close
and restart again. I have add timer between create the procedure and
execute process, but still cause Excel restart. I'm sure nothing wrong
with the new procedure, 'cause when I separate the executing coding,
it's executed succesfully.
My coding is :
Dim VBCodeMod As CodeModule
Dim StartLine As Long
Dim HowManyLines As Long
Dim LineNum As Long
strScript = ""
Set VBCodeMod =
ThisWorkbook.VBProject.VBComponents("Module2").CodeModule
With VBCodeMod
'Delete proc Dynamic_Macro
StartLine = .ProcStartLine("Dynamic_Macro", vbext_pk_Proc)
HowManyLines = .ProcCountLines("Dynamic_Macro",
vbext_pk_Proc)
.DeleteLines StartLine, HowManyLines
'Add again proc Dynamic_Macro
strScript = ""
ReadText "Macro.txt", strScript
LineNum = .CountOfLines + 1
.InsertLines LineNum, strScript
Application.Wait (Now() + TimeValue("0:00:50"))
Application.Run "Dynamic_Macro"
End With
ReadText is a procedure that read Dynamic_Macro content from a file
text "Macro.txt" and pasing to strScript variable.
Please would should I do in order to I can excute it immediately after
created in one procedure?
Thanks for your help,
Resant