1
我將在文件夾中的SVG文件,我已經寫了VBA代碼來獲取XML數據從SVG文件這裏是代碼運行時錯誤1004,沒有數據被選爲解析
Sub Macro4()
Dim lines As Long
Dim letter As String
Dim no As String
Dim count As Integer
Dim i As Integer
Dim xRow As Long
Dim xDirect$, xFname$, InitialFoldr$
count = Sheets.count
If count > 1 Then
For i = 1 To Sheets.count
Sheets(i).Select
On Error GoTo loopexit
If ActiveSheet.Name = "Execute" Then
ElseIf ActiveSheet.Name = "Sheet1" Then
Else
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = False
i = i - 1
End If
Next i
End If
loopexit:
InitialFoldr$ = "C:\"
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Please select a folder to list Files from"
.InitialFileName = InitialFoldr$
.Show
If .SelectedItems.count <> 0 Then
xDirect$ = .SelectedItems(1) & "\"
xFname$ = Dir(xDirect$, 7)
Cells(1, 1).Select
Do While xFname$ <> ""
Application.DisplayAlerts = False
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & xDirect$ & xFname$, Destination:=Range(_
"$A$1"))
.Name = Replace(xFname$, ".svg", "")
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 932
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
Application.DisplayAlerts = False
End With
Rows("1:1").Select
Selection.Insert Shift:=xlDown
lines = ActiveSheet.Range("A65536").End(xlUp).Row
Rows("1:1").Select
Selection.AutoFilter
Range("A1").Select
ActiveSheet.UsedRange.AutoFilter Field:=1, Criteria1:= _
"<>*text transform*", Operator:=xlAnd
ActiveSheet.Range("$A$1:$I$" & lines).Offset(1, 0).SpecialCells _
(xlCellTypeVisible).EntireRow.Delete
Range("A1").Select
Selection.AutoFilter
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:=">", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), _
TrailingMinusNumbers:=True
我得到運行時錯誤1004,所以我決定通過行要執行的代碼行 我申請過濾器來過濾數據「文本轉換」和剩餘的數據我會刪除,所以在代碼
Rows("1:1").Select
Selection.AutoFilter
Range("A1").Select
ActiveSheet.UsedRange.AutoFilter Field:=1, Criteria1:= _
"<>*text transform*", Operator:=xlAnd
ActiveSheet.Range("$A$1:$I$" & lines).Offset(1, 0).SpecialCells _
(xlCellTypeVisible).EntireRow.Delete
它會刪除所有數據的除了「文本轉換」數據,但是當我執行這個過濾器刪除所有DATAS我在XML文件得到如此就說明就行錯誤沒有數據被選爲解析
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:=">", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), _
TrailingMinusNumbers:=True
爲什麼這個錯誤發生任何人可以幫助我糾正它?
請糾正這個問題 – karthikeyan
爲什麼這個錯誤發生? – karthikeyan
請有人幫我在這個錯誤 – karthikeyan