Path returned by Excel VBA

Source: Internet
Author: User

① return to application full path

Application.path

For example: D:SOFTWAREOFFICE2003OFFICE11

② returns the path to the current workbook

Thisworkbook.path

For example: D:

③ returns the current default file path

Application.defaultfilepath

For example: C:documents and Settingsadministratormy Documents

④ only return path

Application.ActiveWorkbook.Path

For example: D:

⑤ return path and workbook file name

Application.ActiveWorkbook.FullName

For example: D:book1.xls

⑥ Return Workbook file name

Application.ActiveWorkbook.Name

For example: Book1.xls

In the above six cases, in the VBA environment, you can also pass the following code test:

MsgBox Application.path

ActiveSheet.Cells (1, 1). Value = Application.path

MsgBox Thisworkbook.path

ActiveSheet.Cells (2, 1). Value = Thisworkbook.path

MsgBox Application.defaultfilepath

ActiveSheet.Cells (3, 1). Value = Application.defaultfilepath

MsgBox Application.ActiveWorkbook.Path

ActiveSheet.Cells (4, 1). Value = Application.ActiveWorkbook.Path

MsgBox Application.ActiveWorkbook.FullName

ActiveSheet.Cells (5, 1). Value = Application.ActiveWorkbook.FullName

MsgBox Application.ActiveWorkbook.Name

ActiveSheet.Cells (6, 1). Value = Application.ActiveWorkbook.Name

In addition, the path-related function, dir, is a function that is specifically used to determine whether a file exists, as in the following code:

application.screenupdating = False

With Application.FileSearch

. FileType = msoFileTypeExcelWorkbooks

. LookIn = Thisworkbook.path

. SearchSubFolders = True

. Execute

If. Execute () > 0 Then

m =. FoundFiles.Count ' current directory and subdirectories total work thin

' MsgBox m

For each F in. FoundFiles ' Make a loop in all the work-sheets

' MsgBox Dir (f) ' lists the name of each workbook, showing only the name, such as Dzwebs.xls, no path

If (Dir (f) <> "Total.xls") Then

Set Xlsapp = New Excel.Application

Set Xlsbook = Workbooks.Open (Thisworkbook.path & "" & Dir (f))

Set Mywantgetsheet = xlsbook.worksheets (1)

For i = 1 to 8

Mywantgetsheet.cells (i, 6). Value = "Www.dzwebs.net"

Next I

Xlsbook.save

Xlsbook.close

Xlsapp.quit

Set Xlsapp = Nothing

Set Xlsbook = Nothing

Set Mywantgetsheet = Nothing

application.screenupdating = True

End If

Next

End If

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.