MultiSelect上的Excel VBA GetOpenFileName错误:= True

林进入错误types不匹配,请帮助我新的vbamacros不知道我在做什么。 我只想让代码能够在search中select多个文件

Sub Main() On Error GoTo Error: 'Open File to search myFile = Application.GetOpenFilename(MultiSelect:=True) bFirstLineExtract = True bFirstLineLog = True CellRowCounter = 2 bFound = False 'Get First Cell Value CellValue = Cells(CellRowCounter, 1) Do Until (CellValue = "") Or (CellValue = Null) Open myFile For Input As #1 Do Until EOF(1) Line Input #1, textline If InStr(textline, CellValue) Then sCreateExtract bFound = True End If Loop If bFound = False Then sCreateLog End If Close #1 CellRowCounter = CellRowCounter + 1 CellValue = Cells(CellRowCounter, 1) Loop Close #1 Exit Sub Error: MsgBox ("Error in Main subroutine - " & Err.Description) End Sub 

就像我在上面的评论中提到的那样

你不能像这样使用myfile 你必须循环收集

看到这个例子。

 Sub Sample() Dim myFile As Variant Dim i As Integer 'Open File to search myFile = Application.GetOpenFilename(MultiSelect:=True) If IsArray(myFile) Then '<~~ If user selects multiple file For i = LBound(myFile) To UBound(myFile) MsgBox myFile(i) Next i Else '<~~ If user selects single file MsgBox myFile End If End Sub