Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在MicrosoftExcel2007中自动进行web查询登录以下载数据?_Excel_Excel Web Query_Vba - Fatal编程技术网

如何在MicrosoftExcel2007中自动进行web查询登录以下载数据?

如何在MicrosoftExcel2007中自动进行web查询登录以下载数据?,excel,excel-web-query,vba,Excel,Excel Web Query,Vba,是否有人可以通过自动启动会话来分享有关如何在Ms.Excel 2007中自动执行web查询的知识 我的问题是,每次我都需要通过web查询手动登录….使用EXCEL的C#COM接口,您可以通过该接口将任何数据注入EXCEL。。。。。。 用以下关键词点击谷歌,你会得到100分的搜索结果 使用Excel=Microsoft.Office.Interop.Excel 现在,上述内容基本上只在ASP.NET中可用。 否则,请使用相应的编程语言获取excel界面 看到这一点,你会有一些想法。以我的经验,这

是否有人可以通过自动启动会话来分享有关如何在Ms.Excel 2007中自动执行web查询的知识

我的问题是,每次我都需要通过web查询手动登录….

使用EXCEL的C#COM接口,您可以通过该接口将任何数据注入EXCEL。。。。。。 用以下关键词点击谷歌,你会得到100分的搜索结果

使用Excel=Microsoft.Office.Interop.Excel

现在,上述内容基本上只在ASP.NET中可用。 否则,请使用相应的编程语言获取excel界面


看到这一点,你会有一些想法。

以我的经验,这是不可能的。Excel的web查询界面没有这样的功能。我已经求助于通过VBA获取web数据,并将其粘贴到一张表中,以自动完成登录部分。请参阅并务必阅读评论。

我遇到了确切的问题

使用一个小小的Vba宏,我可以自动化数据传输。。但我仍然需要手动启动会话

只需少量代码,您就可以自动将数据传输到excel中,您可以使用一些do循环自动逐行记录每个数据。比如,

Do 

If getVars = "" or getVars = Null Then
    Exit Do
End If

Set RangeOfStyles = Range("A1:Z400")

'Clear the xlSheet
For Each Cell In RangeOfStyles
        On Error Resume Next
        ActiveWorkbook.Styles(Cell.Text).Delete
        ActiveWorkbook.Styles(Cell.NumberFormat).Delete
Next Cell

DoEvents
'Use a counter for detecting the range of recieved data in table
'This only works if there is nospace inside the recieved data
'Create a start point
i = 2

'Find the start point
'Will be used if there are some data already found..
'If the starting cell is not empty than start counting
If Cells(i, 2) <> ""  Then

    Do
        Do
            i = i + 1          '2 cause my data starts at column "B2" and row 2
        Loop Until Cells(i + 1, 2) = "" 'if next cell is empty than it ends here
        'im leaving an empty row to seperate each data
        'i must check the row after the empty row to find out if there are more data
        '+1 for empty cell and +1 for starting cell
        i = i + 2
    Loop Until Cells(i, 2) = ""

End If

'Now that we are ready we can paste our next data to the next rows of our worksheet
'Get ur url pasted to the excel
With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;http://127.0.0.1" + getVars, _ 'I used your url here to make it more simpler
    Destination:=Range("B" & i, "I" & i))
    'Use this ability only if you need to gather a specific table in that page
    .WebSelectionType = "xlSpecifiedTables"
    'Webtables = "ChosenTable"
    .WebTables = "10"
    'The other attributes! Nothing fancy here..
    .BackgroundQuery = True
    .TablesOnlyFromHTML = True
    .Refresh BackgroundQuery:=False
    .SaveData = True   
End With


Loop
Do
如果getVars=“”或getVars=Null,则
退出Do
如果结束
设置样式范围=范围(“A1:Z400”)
“清理工作表
对于样式范围中的每个单元格
出错时继续下一步
Active工作簿.样式(单元格.文本).删除
ActiveWorkbook.Styles(Cell.NumberFormat).删除
下一个细胞
多芬特
'使用计数器检测表中接收数据的范围
'仅当接收的数据中没有空间时,此选项才有效
'创建一个起点
i=2
"找到起点,
'将在已找到某些数据时使用。。
'如果起始单元格不为空,则开始计数
如果单元格(i,2)“,则
做
做
i=i+1'2,因为我的数据从“B2”列和第2行开始
循环直到单元格(i+1,2)=“”,如果下一个单元格为空,则循环结束
'我留下一个空行来分隔每个数据
'我必须检查空行后面的行,以确定是否有更多数据
“+1表示空单元格,+1表示起始单元格
i=i+2
循环直到单元格(i,2)=“”
如果结束
'现在我们已经准备好,可以将下一个数据粘贴到工作表的下一行
'获取粘贴到excel的url
使用ActiveSheet.QueryTables.Add(连接:=_
“网址;http://127.0.0.1“+getVars,\我在这里使用了您的url以使其更简单
目的地:=范围(“B”和i,“i”和i))
'仅当需要在该页中收集特定表时,才使用此功能
.WebSelectionType=“xlSpecifiedTables”
'Webtables=“ChosenTable”
.WebTables=“10”
“其他属性!这里没什么特别的。。
.BackgroundQuery=True
.TablesOnlyFromHTML=True
.Refresh BackgroundQuery:=False
.SaveData=True
以
环
您正在使用Excel的内置“Web查询”(qry)功能,对吗?