以下代码是从日志文件中删除重复行的子代码的开头,因此得名。但是,在测试了我到目前为止所拥有的东西之后,我无法理解为什么这会给我一个错误。这是代码:
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”,而相应的描述 fromerr.Description
不存在。
有任何想法吗?
谢谢,QF。