The example in this article mainly realizes the function of VB calling an external exe program to run. Here it mainly uses the shell function to execute. The shell function is mainly used to open an external exe executable file. For example, in the sub module: Shell "notepad", vbNormalFocus represents running the Notepad program in normal mode. vbNormalFocus is a parameter of the shell, which means normal mode. Of course, it also has vbMaximizedFocus maximized mode, vbMinimizedFocus minimized mode, vbHide hidden mode and other running modes to choose from.
Specific code examples and comments are as follows:
VERSION 5.00Begin VB.Form Form1 Caption = "Form1" ClientHeight = 3030 ClientLeft = 120 ClientTop = 450 ClientWidth = 4560 LinkTopic = "Form1" ScaleHeight = 3030 ScaleWidth = 4560 StartUpPosition = 3 'Window default EndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalseOption ExplicitPrivate Sub Form_Load()Shell "notepad", The vbNormalFocus shell function can be used to run an external executable file. Its parameters are: program name (if the program is in a different folder and is not a system file, a detailed path is required), running mode. Suppose you want to run C Packing roots directory's ABC.EXE, the first parameter needs to be: "C://ABC.EXE"' By the way: if there are spaces in the path or file name, you have to add double quotes on both sides of the path (it is recommended regardless of whether there are spaces or not) Add double quotes), like this: """C://1 2.exe """' The second parameter commonly used parameters are: vbNormalFocus normal mode, vbMaximizedFocus maximized mode, vbMinimizedFocus minimized mode, vbHide hidden mode End Sub
After the program is run, the Windows Notepad program will be opened directly. Interested readers can try to open other executable programs to test the running effect, or make personalized modifications to achieve richer functions.