数据连接导入问题
Data connection import problems
我对 VBA 还是有点陌生,我遇到了一些小问题。我有一个数据连接设置,并且导入从 table 中提取所有数据。我 运行 遇到的问题是第三列包含一个 16 位长的数字。当导入发生时,我需要将此列作为文本字段导入,否则导入会将最后一位数字替换为 0。这是我的导入代码。任何帮助将不胜感激。
Worksheets("Equip Related").Visible = True
Dim WK As Worksheet
Application.ScreenUpdating = False
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Feedback").Delete
On Error GoTo 0
Sheets.Add.Name = "Feedback"
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;WEB ADDRESS HERE", Destination:= _
Range("$A"))
.Name = "feedbacklog"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
您可以将查询表中的结果放入结果对象中并设置每列的数据类型:
Set myResults = ActiveSheet.QueryTables.Add(Connection:= _
"URL;WEB ADDRESS HERE", Destination:= _
Range("$A"))
With myResults
.TextFileColumnDataTypes := _
Array(xlGeneralFormat, xlGeneralFormat, xlTextFormat)
.Refresh
End With
我对 VBA 还是有点陌生,我遇到了一些小问题。我有一个数据连接设置,并且导入从 table 中提取所有数据。我 运行 遇到的问题是第三列包含一个 16 位长的数字。当导入发生时,我需要将此列作为文本字段导入,否则导入会将最后一位数字替换为 0。这是我的导入代码。任何帮助将不胜感激。
Worksheets("Equip Related").Visible = True
Dim WK As Worksheet
Application.ScreenUpdating = False
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Feedback").Delete
On Error GoTo 0
Sheets.Add.Name = "Feedback"
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;WEB ADDRESS HERE", Destination:= _
Range("$A"))
.Name = "feedbacklog"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
您可以将查询表中的结果放入结果对象中并设置每列的数据类型:
Set myResults = ActiveSheet.QueryTables.Add(Connection:= _
"URL;WEB ADDRESS HERE", Destination:= _
Range("$A"))
With myResults
.TextFileColumnDataTypes := _
Array(xlGeneralFormat, xlGeneralFormat, xlTextFormat)
.Refresh
End With