以下代码是从一个日志文件中删除重复行的子开头,因此是该名称。然而,在测试了我到目前为止的内容后,我无法理解为什么这会给我一个错误。这里的代码: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!干杯,谢谢。 – 2012-04-26 10:50:14