VBA Excel 提示用户 select 默认文件夹中的文件
VBA Excel prompt user to select a file in a default folder
我想提示用户打开默认文件夹中的 Excel 文件。我不知道如何打开默认文件夹。
Sub Program1()
DefaultFolder = "C:\user\dump"
FName = Application.GetOpenFilename
If FName <> False Then
Set WorkB2 = Workbooks.Open(FName)
' some codes here
End If
End Sub
使用 chdir:
Sub Program1()
Chdir "C:\user\dump"
FName = Application.GetOpenFilename
If FName <> False Then
Set WorkB2 = Workbooks.Open(FName)
' some codes here
End If
End Sub
这是打开 excel 文件的示例
Option Explicit
Sub OpenFile()
Dim xlFile As Variant
ChDir "C:\temp"
'// Showing Excel Dialog
xlFile = Application.GetOpenFilename("All Excel Files (*.xls*)," & _
"*.xls*", 1, "Select Excel File", "Open", False)
'// If Cancel then exit
If TypeName(xlFile) = "Boolean" Then
Exit Sub
End If
'// Open selected file
Workbooks.Open xlFile
End Sub
我想提示用户打开默认文件夹中的 Excel 文件。我不知道如何打开默认文件夹。
Sub Program1()
DefaultFolder = "C:\user\dump"
FName = Application.GetOpenFilename
If FName <> False Then
Set WorkB2 = Workbooks.Open(FName)
' some codes here
End If
End Sub
使用 chdir:
Sub Program1()
Chdir "C:\user\dump"
FName = Application.GetOpenFilename
If FName <> False Then
Set WorkB2 = Workbooks.Open(FName)
' some codes here
End If
End Sub
这是打开 excel 文件的示例
Option Explicit
Sub OpenFile()
Dim xlFile As Variant
ChDir "C:\temp"
'// Showing Excel Dialog
xlFile = Application.GetOpenFilename("All Excel Files (*.xls*)," & _
"*.xls*", 1, "Select Excel File", "Open", False)
'// If Cancel then exit
If TypeName(xlFile) = "Boolean" Then
Exit Sub
End If
'// Open selected file
Workbooks.Open xlFile
End Sub