我正在尝试使用打开的文件填充列表框。整个过程会将选定的工作表从现有文件导出到另一个工作簿,并将其保存为附加到同一目录的日期时间戳。它根据表单列表框中的项目构建此导出名称和文件。
宏将从 Personal.XLSB 运行;问题是这成为活动工作簿,导出的文件从它继承路径和文件名。我想通过让用户从列表框中选择一个文件名来构建导出名称,但是我不希望 Personal.XLSB 显示在列表中,此外,一旦用户选择了文件名(从打开的列表中文件)我想让该文件成为活动文件。我花了三个小时进行许多变化的 INSTR(使用数字或仅使用文本)甚至文本比较,或者在下面的“instr”中使用“PERSONAL.xlsb”,但我根本无法让它工作。有没有过这样的一天??????
任何人都可以提供任何见解?
代码如下:
' Populate the open file name list box excluding Personal.xlsb
Dim wbOpen As Workbook
Dim wbopenText As String
ListBoxOpenFiles.Clear
For Each wbOpen In Workbooks
wbopenText = wbOpen.Name
If InStr(1, wbopenText, "Per") = 0 Then
ListBoxOpenFiles.AddItem wbOpen.Name ' add the name to the list
MsgBox wbOpen.Name & "Added to list"
End If
If InStr(1, wbopenText, "Per") = 1 Then ' If "Personal" is NOT found skip
End If 'Loop again
Next
' next step - make the existing file the active workbook
'still to do