vba怎麼獲取當前文件夾路徑?Sub getPath()Range("A1") = "路徑名稱",接下來我們就來聊聊關于vba怎麼獲取當前文件夾路徑?以下内容大家不妨參考一二希望能幫到您!
Sub getPath()
Range("A1") = "路徑名稱"
Range("B1") = "具體路徑"
Range("A2") = "SystemDrive"
Range("B2") = Environ("SystemDrive")
Range("A3") = "TEMP"
Range("B3") = Environ("TEMP")
Range("A4") = "windir"
Range("B4") = Environ("windir")
Range("A5") = "SystemRoot"
Range("B5") = Environ("SystemRoot")
Range("A6") = "ProgramFiles"
Range("B6") = Environ("ProgramFiles")
Range("A7") = "Application.path"
Range("B7") = Application.Path
Range("A8") = "Application.StartupPath"
Range("B8") = Application.StartupPath
Range("A9") = "Application.TemplatesPath"
Range("B9") = Application.TemplatesPath
Range("A10") = "Application.UserLibraryPath"
Range("B10") = Application.UserLibraryPath
Range("A11") = "Application.DefaultFilePath"
Range("B11") = Application.DefaultFilePath
路徑變量 具體路徑 SystemDrive C: TEMP C:\Users\WWUHNW~1\AppData\Local\Temp windir C:\Windows SystemRoot C:\Windows ProgramFiles C:\Program Files Application.path C:\Program Files\Microsoft Office\Office12 Application.StartupPath C:\Users\username\AppData\Roaming\Microsoft\Excel\XLSTART Application.TemplatesPath C:\Users\username\AppData\Roaming\Microsoft\Templates\ Application.UserLibraryPath C:\Users\username\AppData\Roaming\Microsoft\AddIns\ 2 按照選擇的路徑打開指定的文件夾 Application.DefaultFilePath C:\Users\username\Documents 選中地址所在單元格,運行下述代碼即可打開指定的文件夾。
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal sParam As Long, ByVal lParam As Long) As Long
Private Const WM_CLOSE As Long = &H10
'以上代碼聲明API函數和常量
Public Sub OpenDirectory()
Dim path1 As String
path1 = ActiveCell
ShellExecute 0, "", "", "", path1, 1
End Sub
Public Sub CloseDirectory()
Dim hWnd As Long
hWnd = FindWindows(vbNullString, "C:\Program Files\Microsoft Office\Office12")
PostMessage hWnd, WM_CLOSE, 0, 0
End Sub
,更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!