次のコードは、ログファイルから重複した行を削除するサブの始まりです。しかし、私がこれまでに行ったことをテストした後、なぜこれが私にエラーを与えているのか理解できません。コードは次のとおりです。VBA - なぜ私にエラーが表示されますか?
Sub cleanUpLogFile()
Dim logFileStr As String
Dim newBook As Workbook
Dim fd1 As FileDialog
MsgBox "Select your log file.", vbInformation, "Important Info"
Set fd1 = Application.FileDialog(msoFileDialogFilePicker)
With fd1
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "*.xl* Files", "*.xl*", 1
'if user selects a file then
If .Show Then
'assign selection to variable
logFileStr = fd1.SelectedItems.Item(1)
Else 'display prompt and exit sub
MsgBox "You didn't select your indexation file. Exiting...", _
vbCritical, "Important Info"
Exit Sub
End If
End With
Set newBook = Workbooks.Open(logFileStr, 0)
newBook.Close (0)
Set newBook = Nothing
MsgBox "finished"
errHandler:
MsgBox "Encountered an error: " & Err.Number & " -> " & Err.Description, _
vbExclamation, "Error! - from cleanUpLogFile() sub"
Err.Clear
Exit Sub
End Sub
エラーメッセージボックスでも多くの情報がわかりません。 err.Number
は「0」と表示され、err.Description
の対応する説明は存在しません。
アイデア?
ありがとう、 QF。
Doh!乾杯、ありがとう。 –