VBA 怎么打开excel
这里举个打开文件器选择文件,然后在读取改路径,打开excel
Private Sub CommandButton3_Click()
'选择单一文件
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False '单选择
.Filters.Clear '清除文件过滤器
.Filters.Add "Excel Files", "*.xlsx" '设置两个文件过滤器
If .Show = -1 Then 'FileDialog 对象的 Show 方法显示对话框,并且返回 -1(如果您按 OK)和 0(如果您按 Cancel)
ThisWorkbook.Sheets(1).Cells(6, 4).Value = .SelectedItems(1)
End If
End With
End Sub
Dim wk As Workbook '目标文件
Dim xl As Object
Dim exPath As String
exPath = ThisWorkbook.Sheets(1).Cells(6, 4).Value
Set wk = Workbooks.Open(exPath)
Set ws = wk.Worksheets(1)