使用excel中的范围从网页中提取结果
我正试图通过网络将数据提取到excel中。下面的代码工作正常,但是没有URL;在代码主体中,我希望链接到Excel ie=RangeB2中具有该引用的特定单元格,以便在选择更改和刷新时提取正确的数据。我错过了一些东西使用excel中的范围从网页中提取结果,excel,vba,Excel,Vba,我正试图通过网络将数据提取到excel中。下面的代码工作正常,但是没有URL;在代码主体中,我希望链接到Excel ie=RangeB2中具有该引用的特定单元格,以便在选择更改和刷新时提取正确的数据。我错过了一些东西 Sub GetData() 'Network Extraction With ActiveSheet.QueryTables.Add(Connection:= _ "URL;http://www.gsmarena.com/apple_iphone_6
Sub GetData()
'Network Extraction
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.gsmarena.com/apple_iphone_6-6378.php", Destination:=Range( _
"$C$4"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "1"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
根据指导,OP@Stewart Setter的回答已从问题中删去,并作为答案
作者文本:
我现在已经解决了这个问题。见下文。我使用Connstring=RangeA2,并将URL网址替换为Connection:=Connstring
Sub GetData()
Connstring = Range("A2")
With ActiveSheet.QueryTables.Add(Connection:=Connstring, Destination:=Range( _
"$C$24"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "4"
.WebPreFormattedTextToColumns = False 'xx
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
我算出来了。我使用了connstring=RangeA2,然后是Connection:=connstring,这非常有效。你能为这个问题添加你自己的答案并接受它,让其他人知道这个问题已经解决了吗?@StewartSetter。答案不应编辑到问题中。如果你想回答你的问题,例如为了赢得代表,只需在社区维基答案上留下评论,我将删除它。