Iamlaosong
Baidu a bit. Very easy to find Debug.Print explain and use introduction. It's actually very simple. is to display the results of the code run in the immediate form, without affecting the program running. during the debugging of a VBA program, it is often necessary to monitor the value of the variable, although MsgBox can also complete this function, but with Debug.Print Displays the value of a variable or expression. Have a lot of advantages. Details such as the following:
1, does not affect the program operation. despite MsgBox can also display code running results, but each time to press OK button to continue, encountered large circular statement simply can not be carried out;
2, after the completion of the program debugging. These debug statements should be masked. But even if there is a legacy of Debug.Print does not affect user use. MsgBox is not good;
3, the biggest advantage is: for the value of the variable, can be in the "immediate form" slowly study, can be copied out of the study, for example, we want to synthesize an SQL statement. But there was an error in the operation, where was it wrong? The variables and values in the program are mixed together and it's hard to find the wrong point. Especially when the numbers and parentheses are large. Copy the synthesized SQL statement and run it, you can easily find the problem,MsgBox not.
By the way, right away. Form ( Press Ctrl+g or menu to select ), in addition to displaying the running results of the Debug.Print. The form is also able to enter statements directly during debugging. Press ENTER to display the result of the statement, you can also use the "? Variable name to display the value of the variable (although the value of the variable is displayed when the mouse is over the variable, assuming that the value is too long to be displayed). For example, suppose you have a variable that is mystr, and you can enter the following example in the immediate form:
? MyStr
?
Left (mystr,5)
? InStr (MyStr, ":")
If Len (mystr) >0 Then MsgBox mystr
VBA Debugging Tool Debug.Print