Source: http://blog.csdn.net/alexbnlee/article/details/6924207
1→ Implement the standard "open" dialog box and get the user's file name without actually opening any file. Obtain the file FullName.
Expression. GetOpenFilename (FileFilter, FilterIndex, Title, ButtonText, MultiSelect)
FileFilter: filter file Title: Title MultiSelect: You can select multiple
Sub Stop1 () Dim fileInformation As String Dim fi As Workbook fileInformation = Application. getOpenFilename (_ filefilter: = "Excel Workbook (*. xlsx ),*. xlsx ", _ Title: =" open an Excel file ") MsgBox fileInformation Shell" C: \ Program Files \ Microsoft Office \ Office14 \ excel.exe "& fileInformation, vbMaximizedFocusEnd Sub
Application. GetOpenFilename: Stab Me !!!
2→ Shell functions
Execute an executable file and return a Variant (Double). If it succeeds, it indicates the task ID of the program. If it fails, it returns 0.
Syntax
Shell (pathname [, windowstyle])
Shell "C: \ WINDOWS \ system32 \ calc. EXE", 1' to complete Calculator.
You can also do this:
Sub djfkl () Dim RetVal = Shell ("C: \ WINDOWS \ system32 \ calc. EXE", 1) 'to complete Calculator. End Sub
Shell function: Stab Me !!!
3→ Open a text file reference: http://infos.edulife.com.cn/200503/2005038517.html
4→ Use Shell functions to open non-executable files
Method: Shell "App. PathFile. Path", vbMaximizedFocus
The address is divided into three parts. The first part is the executable program location, the second part is a space, and the third part is the path to open the file.
Shell "C:\Program Files\Microsoft Office\Office14\excel.exe " & fileInformation, vbMaximizedFocus
Is how to open an Excel file ~
Dim filePath As StringfilePath = Application.GetOpenFilename("Excel(*.xlsx), *.xlsx", 1, "Open Excel")If Len(filePath) > 5 Then Shell "C:\Program Files\Microsoft Office\Office14\excel.exe " & filePath, vbMaximizedFocusElse MsgBox "Sorry!!!"End If
5→ Add Workbook
Workbook. add' adds a Workbook
Workbooks. Open Filename: = ThisWorkbook. Path & "\ workbook-" & I & ". xlsx"
Open a file at a specified location
6→ Close Workbook
ActiveWorkbook. Close SaveChanges: = True, Filename: = ThisWorkbook. Path & "\ workbook 1"
The first parameter indicates save change, the second parameter indicates the name of the workbook, and the path can be added.
Sub addSheet () For I = 1 To 10 Workbooks. add For j = 1 To 10 Cells (j, 1) = j Next ActiveWorkbook. close savechanges: = True, Filename: = ThisWorkbook. path & "\ workbook-" & I NextEnd Sub
Window Maximization
Application.WindowState = xlMaximized
Minimize windows
Window Normalization