[C002] Excel VBA-Close file opening

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.