Part 1:引言

vba如何选定当前工作簿(VBA常用函数打开文件窗口1)(1)

Part 2:VBA代码实现

Sub test() Set objFSO = CreateObject("Scripting.FileSystemObject") With Application.FileDialog(msoFileDialogOpen) .Title = "请选择文件" .AllowMultiSelect = True .Filters.Clear .Filters.Add "Excel文件", "*.xlsx;*.txt;*.xlsm" .FilterIndex = 2 .InitialFileName = ThisWorkbook.Path .Show For Each wenJian In .SelectedItems longName = wenJian shortName = objFSO.GetFileName(wenJian) Debug.Print ("longName=" & longName) Debug.Print ("shortName=" & shortName) Call File_Insert(longName, shortName) Next End With End Sub

Part 3:部分代码解读

,