Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Error when Execute New Procedure Created Using VBE

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").Cod eModule

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Error when Execute New Procedure Created Using VBE

Resant,

I haven't tested this, but maybe if you force a re-compile in the code it
might work

Application.VBE.CommandBars.FindControl(ID:=578).E xecute

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Resant" wrote in message
ps.com...
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").Cod eModule

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Error when Execute New Procedure Created Using VBE

Thanks for your reply, Bob
But it's still doesn't work. The Excel still restart.
Any other idea please?


Bob Phillips wrote:
Resant,

I haven't tested this, but maybe if you force a re-compile in the code it
might work

Application.VBE.CommandBars.FindControl(ID:=578).E xecute

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Resant" wrote in message
ps.com...
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").Cod eModule

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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can I execute stored procedure to download data Bill[_36_] Excel Programming 1 December 1st 05 07:03 PM
execute stored procedure from excel maxzsim Excel Worksheet Functions 3 May 11th 05 04:58 PM
execute stored procedure Mark Goldin Excel Programming 3 April 7th 04 03:03 PM
Execute procedure on startup Richard[_20_] Excel Programming 4 March 3rd 04 11:36 AM
Execute stored procedure using DAO sapta wijaya Excel Programming 0 September 29th 03 04:24 AM


All times are GMT +1. The time now is 04:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"