gpt4 book ai didi

Excel VBA GetOpenFileName 多选时出错 :=True

转载 作者:行者123 更新时间:2023-12-03 02:03:42 29 4
gpt4 key购买 nike

我收到错误类型不匹配的错误。请帮助,因为我是 VBA 宏的新手,不确定我在做什么。我只是希望代码能够在搜索时选择多个文件:

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

关于Excel VBA GetOpenFileName 多选时出错 :=True,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25180061/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com