' Add a command and text
Private Declare Function Ebexecuteline Lib " Vba6.dll " ( Byval Pstringtoexec As Long , Byval Unknownn1 As Long , Byval Unknownn2 As Long , Byval Fcheckonly As Long ) As Long
Function Executeline (scode As String , Optional Fcheckonly As Boolean ) As Boolean
Executeline = ebexecuteline (strptr (scode ), 0 &, 0 &, ABS (Fcheckonly) = 0
End Function
Private Sub Commandmediaclick ()
Dim DM () As String
Dim I As Long
Dm = Split (Text1, vbcrlf)
For I = 0 To Ubound (DM)
If Len (DM (I) <> 0 Then
Dim Result As Boolean
Result = executeline (DM (I ))
If Result = False Then Debug. Print I + 1 & Vbtab & " Row execution error "
Else
Debug. Print I + 1 & Vbtab & " LineCodeError "
End If
Next
End sub
AboveProgramAfter execution, enter the VB Code (for example, msgbox "VB") in text1 and click command1 to execute the VB code in text1. If a line of code is empty, a line of code error is prompted, if a syntax error occurs in the line code, the system will prompt the line execution error. (ALL prompts are displayed in the prompt window)
The above code has room for improvement (such as prompting why the error occurs, changing the syntax color, and so on)
girls do not cry (QQ: 191035066) @ 2011-12-23 22:08:41
http://www.cnblogs.com/nbsofer/archive/2011/12/23/2298788.html