Excel Web扫描

我遇到了networking报废Excel问题。 我想从这个网站的数据:charitynavigator.org

我正在这个链接列表上进行testing运行: http : //www.charitynavigator.org/index.cfm?bay= search.results& cgid=7&cuid=30

我通过第一个链接(The Aims Project)logging了一个macros。 然后,我添加了一个在YouTubevideo中使用的“循环”(?)。 video制作者解释了代码的逻辑,所以循环似乎是有道理的,并适用于我的问题。 但是,抓取第一页后,程序无法进入下一个网页。

这是我的代码

Sub adds() 'For i = 1 to 5 For x = 1 To 5 Worksheets("IntlHum").Select Worksheets("IntlHum").Activate mystr = "URL;http://www.charitynavigator.org/index.cfm?bay=search.summary&orgid=3803" mystr = Cells(x, 1) Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = x With ActiveSheet.QueryTables.Add(Connection:= _ mystr, _ Destination:=Range("$A$1")) '.CommandType = 0 .Name = "index.cfm?bay=search.summary&orgid=3803_1" .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 = "2,3,4,5" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With Next x End Sub 

YouTube的video是https://www.youtube.com/watch?v=qbOdUaf4yfI我是一个完整的新手。 我理解逻辑,与STATA和LaTexx合作过,但我不是计算机科学家。 请保持行话最小。 谢谢!

在第二遍( x = 2 )中,“ActiveSheet”的概念可能已经改变了,所以mystr = Cells(x, 1)不会返回期望值,因为它可能会从你想要的不同数据源读取。 (有关更多详细信息,请参阅Office.Cells属性(Excel)文档 )。 “ActiveSheet”的更改是作为调用Officeheets的Office文档的副作用完成的.Add方法(Excel)

将其更改为mystr = Worksheets("IntlHum").Cells(x, 1)可能有所帮助。

但是我的答案是学习如何使用Excel VBAdebugging ,包括“步入(F8)”,“立即打印窗口”等。

这是任何严重的Excel VBA必须学习的工具,这是用来解决你的代码的工具。

Excel VBA(和一般的Visual Basic)并没有为计算机科学家devise(或打算),而是“为了群众”,所以你应该很容易地find自己的方式(在学习了一些必要的术语之后)。

您应该能够find许多与Google使用的当前技能相匹配的教程资源。 作为一个这样的资源,你可以尝试http://www.excel-easy.com/vba/examples/debugging.html