将表格数据从多个网页拉入工作簿

时间:2014-06-23 14:38:31

标签: excel vba excel-web-query

我正在尝试在VBA中编写一个宏,将一些网页的数据表拉入excel。将为每个网页/表创建一个新工作簿。

每个网页都有一个表格,每个页面都有相同的布局。每个页面的网址格式相同,网址末尾有数字标识符。

不幸的是,该网站本身受密码保护。

到目前为止,我已经能够记录一个宏,我在其中为单个页面/表创建Web查询。此时,我无法弄清楚如何为大量页面重复该过程,以及如何以为每个页面创建新工作簿的方式编写宏。如果用户可以输入标识符列表(URL末尾的数字),运行宏,并为每个页面生成一个单独的文件,那将是很棒的。

Sub productiondata()
'
' productiondata Macro
' pulls production table from dmr site for well number 19918
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;https://www.dmr.nd.gov/oilgas/feeservices/getwellprod.asp?filenumber=19918" _
        , Destination:=Range("$A$1"))
        .Name = "getwellprod.asp?filenumber=19918"
        .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 = "3"
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
End Sub

提前感谢您提供任何指导!

更新(2014年6月24日):

我设法对代码进行了一些更改,现在它将创建一个新工作簿并将数据导入到新工作簿中:

Sub productiondata()
'create new workbook named after the value in cell A1
Dim Aname As String
Aname = ActiveWorkbook.Sheets(1).Range("A1").Value
Workbooks.Add
ActiveWorkbook.SaveAs Filename:=Aname & ".xls"
' productiondata Macro
' pulls production table from dmr site for well number 25158
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;https://www.dmr.nd.gov/oilgas/feeservices/getwellprod.asp?filenumber=25158" _
        , Destination:=Range("$A$1"))
        .Name = "getwellprod.asp?filenumber=25158"
        .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 = "3"
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
End Sub

我现在正试图弄清楚如何更改网页查询,以便将单元格A1中的数字附加到网址。

更新(2014年6月24日):

以下是其中一个受密码保护的网页(https://www.dmr.nd.gov/oilgas/feeservices/getwellprod.asp?filenumber=22809)的示例的源代码我试图从中提取表格:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Retrieve Well Production Data</title>
<link rel="stylesheet" type="text/css" href="/css/stateBanner.css">
<link rel="stylesheet" type="text/css" href="/css/oilGasDefaults.css">
<link rel="stylesheet" type="text/css" href="/css/jqueryOGDUI/css/custom-theme/jquery-ui-1.9.1.custom.css" >
<style type="text/css">
    .menuBar {
        width: 155px;
        font: 10px verdana,sans-serif;
    }
    .menuBtn {
        width: 100%;
    }
    .menuHeader {
        background-color: #FFFF00;
        padding: 1px;
        margin: 1px; 
        font-size: larger; 
        font-weight: bold;
        text-align: center;
    }
</style>
<script language="javascript" type="text/javascript" src="/includes/oilandgas.js"></script>
<script language="javascript" type="text/javascript" src="/includes/left-nav.js"></script>
<script language="javascript" type="text/javascript" src="/css/jqueryOGDUI/js/jquery-1.8.2.js"></script>
<script language="javascript" type="text/javascript" src="/css/jqueryOGDUI/js/jquery-ui-1.9.1.custom.js"></script>
<script>
$(function() {
    $( "#premiumServiceBtn" ).button().click(function() { location.href='../subscriptionservice.asp'; });
    $( "#scoutTicketBtn" ).button().click(function() { location.href='getscoutticket.asp'; });
    $( "#digImgLogsBtn" ).button().click(function() { location.href='getlogs.asp'; });
    $( "#fieldProdBtn" ).button().click(function() { location.href='fieldprodinj.asp'; });
    $( "#launchIMSWellBBtn" ).button().click(function() { location.href='javascript:launchIMSSubWell("22809");'; });    $( "#getWellFileBBtn" ).button().click(function() { location.href='/oilgas/FeeServices/wfiles/22/W22809.pdf'; });
});
</script>
</head>

<body onload="document.forms[0].elements[0].focus(); document.forms[0].elements[0].select()">
<div style="margin:0; padding:0; width:100%; background:#fff; height:26px; border-bottom:1px solid #ccc"><div style="float:left"><span style="display:none">[</span><a href="http://www.nd.gov/"><img style="border-width:0" src="/images/ndgov-banner.gif" height="25" alt="nd.gov - The Official Portal for North Dakota State Government" /></a><span style="display:none">]</span></div><div style="float:right"><span style="display:none">[</span><a href="http://www.ndtourism.com/"><img style="border-width:0" src="/images/tourism-banner-blue.gif" width="95" height="25" alt="North Dakota: Legendary. Follow the trail of legends" /></a><span style="display:none">]</span></div></div>
<table border="0" cellpadding="0" cellspacing="0" width="100%" summary="NDIC Get Well Production Header Table" height="0%">
<tr>
<td width="0%" valign="top" align="left" height="0%">
    <div class="menuBar">
        <div class="menuHeader">Related Links</div>
        <button id="premiumServiceBtn" class="menuBtn">Premium Services</button>
        <button id="scoutTicketBtn" class="menuBtn">Scout Ticket Data</button>
        <button id="digImgLogsBtn" class="menuBtn">Digital & Image Logs</button>
        <button id="fieldProdBtn" class="menuBtn">Field Production</button>
<button id="launchIMSWellBBtn" class="menuBtn">Map This Well</button><button id="getWellFileBBtn" class="menuBtn">Get Well File</button>
    </div>
    <div id="nonFocus"></div>
 </td>
 <td height="0%" width="80%">
  <script Language="JavaScript"><!--
function FrontPage_Form1_Validator(theForm)
{

  if (theForm.FileNumber.value == "")
  {
    alert("Please enter a value for the \"File Number\" field.");
    theForm.FileNumber.focus();
    return (false);
  }

  if (theForm.FileNumber.value.length > 5)
  {
    alert("Please enter at most 5 characters in the \"File Number\" field.");
    theForm.FileNumber.focus();
    return (false);
  }

  var checkOK = "0123456789-";
  var checkStr = theForm.FileNumber.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"File Number\" field.");
    theForm.FileNumber.focus();
    return (false);
  }
  return (true);
}
//--></script><form method="POST" action="/oilgas/feeservices/getwellprod.asp" onsubmit="return FrontPage_Form1_Validator(this)" name="FrontPage_Form1">
  <h2 align="center">Get Well Production History Data</h2>
  <p align="center"><Label for="fileno">Enter File Number:</Label>              
  <input type="text" name="FileNumber" size="5" id="fileno"
  value="0" maxlength="5"></p>
  <p align="center"><input type="submit" value="Get Monthly Production Data"
  name="B1"></p>
  </form>
 </td>
 <td valign="top" align="right" nowrap width="20%" height="0%"><a href="https://www.dmr.nd.gov/oilgas/"><img border="0" src="https://www.dmr.nd.gov/oilgas/images/ogdmrlogosmall.gif"  width="108" height="67" alt="Return to Oil & Gas Home Page"></a></td>
 </tr>
</table>

<table border="0" cellpadding="0" cellspacing="0" width="98%" align="center" summary="Well data content table" height="0%">
<tr>
<td>
<div>NDIC File No: <b>22809</b> &#xa0;&#xa0;&#xa0; API No: <b>33-023-00836-00-00</b> &#xa0;&#xa0;&#xa0; CTB No: <b>122809</b><br>
Well Type: <b><span title="Oil & Gas">OG</span></b> &#xa0;&#xa0;&#xa0; Well Status: <b><span title="Active">A</span></b> &#xa0;&#xa0;&#xa0; Status Date: <b>10/5/2012</b> &#xa0;&#xa0;&#xa0; Wellbore type: <b>Horizontal</b><br>
Location: <b>NWNE 15-163-99</b> &#xa0;&#xa0;&#xa0; Footages: <b>298 FNL 1998 FEL</b> &#xa0;&#xa0;&#xa0; Latitude: <b>48.951490</b> &#xa0;&#xa0;&#xa0; Longitude: <b>-103.516702</b><br>
Current Operator: <b>SAMSON RESOURCES COMPANY</b><br>
Current Well Name: <b>BAJA  1522-04TFH</b><br>
Elevation(s):<b>&#xa0;2117 <span title="Kelly Bushing">KB</span>&#xa0; </b><b>&#xa0;2097 <span title="Graded Ground Level">GR</span>&#xa0; </b><b>&#xa0;2091 <span title="Original Ground Level">GL</span>&#xa0; </b> &#xa0;&#xa0; Total Depth: <b>17485 </b> &#xa0;&#xa0;&#xa0; Field: <a href=/oilgas/FeeServices/OrderIndex.asp?SELECTFIELD=AMBROSE><b><span title="Go to the AMBROSE Field Order Index">AMBROSE</span></b></a><br>
Spud Date(s):&#xa0;&#xa0;<b>7/9/2012</b><br>
Casing String(s):  <b>9.625" 1528'&#xa0;&#xa0;</b> <b>7" 8304'&#xa0;&#xa0;</b><br>
Completion Data<br>
&#xa0;&#xa0;&#xa0;Pool: <b>BAKKEN</b> &#xa0;&#xa0;&#xa0; Perfs: <b>8304-17485</b> &#xa0;&#xa0;&#xa0; Comp: <b>10/5/2012</b> &#xa0;&#xa0;&#xa0; Status: <b><span title="Producing by Artificial Lift">AL</span></b> &#xa0;&#xa0;&#xa0; Date: <b>10/22/2012</b> &#xa0;&#xa0;&#xa0; Spacing: <b><span title="1280 Acres, 2 Sections
Secs 15&22-163-99">2SEC</span></b><br>
Cumulative Production Data<br>
&#xa0;&#xa0;&#xa0;Pool: <b>BAKKEN</b> &#xa0;&#xa0;&#xa0; Cum Oil: <b>37552</b> &#xa0;&#xa0;&#xa0; Cum MCF Gas: <b>39854</b> &#xa0;&#xa0;&#xa0; Cum Water: <b>44995</b> &#xa0;&#xa0;&#xa0; [<a href="javascript: launchDecline('well','22809|BAKKEN');"><span title="Use the interactive curve program for the BAKKEN Pool (Requires Adobe Flash player)">Interactive Performance Curve</span></a>]
 [<a href="javascript:launchPDFPerfCurve('W7E0B2C4D22809');"><span title="Generate a PDF performance curve for the BAKKEN pool for this well">PDF Curve</span></a>]<br>
Production Test Data<br>
&#xa0;&#xa0;&#xa0;<span title="Initial Production Test">IP Test</span> Date: <b>10/22/2012</b> &#xa0;&#xa0;&#xa0; Pool: <b>BAKKEN</b> &#xa0;&#xa0;&#xa0; IP Oil: <b>315</b> &#xa0;&#xa0;&#xa0; IP MCF: <b>308</b> &#xa0;&#xa0;&#xa0; IP Water: <b>364</b><br>
</td></tr><td>Monthly Production Data<br>
<table style="border:1px solid saddlebrown;" cellpadding="4" cellspacing="0" width="100%" align="center" summary="Monthly production data content table" height="0%">
<thead><th style="border:1px solid saddlebrown;"><span title="Pool oil and/or gas was produced from">Pool</span></th><th style="border:1px solid saddlebrown;"><span title="Month and Year produced">Date</span></th><th style="border:1px solid saddlebrown;"><span title="Number of days the well produced during the month">Days</span></th><th style="border:1px solid saddlebrown;"><span title="Barrels of oil produced">BBLS Oil</span></th><th style="border:1px solid saddlebrown;"><span title="Barrels of oil sold">Runs</span></th><th style="border:1px solid saddlebrown;"><span title="Barrels of water produced">BBLS Water</th><th style="border:1px solid saddlebrown;"><span title="Thousand cubic feet of gas produced">MCF Prod</span></th><th style="border:1px solid saddlebrown;"><span title="Thousand cubic feet of gas sold">MCF Sold</span></th><th style="border:1px solid saddlebrown;"><span title="Thousand cubic feet of gas vented or flared">Vent/Flare</span></th></thead>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">4-2014</td><td style="border:1px solid saddlebrown;" align="right">3</td><td style="border:1px solid saddlebrown;" align="right">26</td><td style="border:1px solid saddlebrown;" align="right">408</td><td style="border:1px solid saddlebrown;" align="right">0</td><td style="border:1px solid saddlebrown;" align="right">61</td><td style="border:1px solid saddlebrown;" align="right">61</td><td style="border:1px solid saddlebrown;" align="right">0</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">3-2014</td><td style="border:1px solid saddlebrown;" align="right">22</td><td style="border:1px solid saddlebrown;" align="right">790</td><td style="border:1px solid saddlebrown;" align="right">250</td><td style="border:1px solid saddlebrown;" align="right">958</td><td style="border:1px solid saddlebrown;" align="right">958</td><td style="border:1px solid saddlebrown;" align="right">652</td><td style="border:1px solid saddlebrown;" align="right">100</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">2-2014</td><td style="border:1px solid saddlebrown;" align="right">7</td><td style="border:1px solid saddlebrown;" align="right">359</td><td style="border:1px solid saddlebrown;" align="right">240</td><td style="border:1px solid saddlebrown;" align="right">549</td><td style="border:1px solid saddlebrown;" align="right">274</td><td style="border:1px solid saddlebrown;" align="right">147</td><td style="border:1px solid saddlebrown;" align="right">69</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">1-2014</td><td style="border:1px solid saddlebrown;" align="right">17</td><td style="border:1px solid saddlebrown;" align="right">609</td><td style="border:1px solid saddlebrown;" align="right">469</td><td style="border:1px solid saddlebrown;" align="right">998</td><td style="border:1px solid saddlebrown;" align="right">604</td><td style="border:1px solid saddlebrown;" align="right">283</td><td style="border:1px solid saddlebrown;" align="right">161</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">12-2013</td><td style="border:1px solid saddlebrown;" align="right">26</td><td style="border:1px solid saddlebrown;" align="right">927</td><td style="border:1px solid saddlebrown;" align="right">1453</td><td style="border:1px solid saddlebrown;" align="right">1370</td><td style="border:1px solid saddlebrown;" align="right">1190</td><td style="border:1px solid saddlebrown;" align="right">558</td><td style="border:1px solid saddlebrown;" align="right">382</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">11-2013</td><td style="border:1px solid saddlebrown;" align="right">25</td><td style="border:1px solid saddlebrown;" align="right">980</td><td style="border:1px solid saddlebrown;" align="right">651</td><td style="border:1px solid saddlebrown;" align="right">1543</td><td style="border:1px solid saddlebrown;" align="right">1145</td><td style="border:1px solid saddlebrown;" align="right">660</td><td style="border:1px solid saddlebrown;" align="right">245</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">10-2013</td><td style="border:1px solid saddlebrown;" align="right">31</td><td style="border:1px solid saddlebrown;" align="right">1125</td><td style="border:1px solid saddlebrown;" align="right">1181</td><td style="border:1px solid saddlebrown;" align="right">1049</td><td style="border:1px solid saddlebrown;" align="right">1335</td><td style="border:1px solid saddlebrown;" align="right">818</td><td style="border:1px solid saddlebrown;" align="right">246</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">9-2013</td><td style="border:1px solid saddlebrown;" align="right">29</td><td style="border:1px solid saddlebrown;" align="right">1177</td><td style="border:1px solid saddlebrown;" align="right">1182</td><td style="border:1px solid saddlebrown;" align="right">1213</td><td style="border:1px solid saddlebrown;" align="right">1347</td><td style="border:1px solid saddlebrown;" align="right">1059</td><td style="border:1px solid saddlebrown;" align="right">0</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">8-2013</td><td style="border:1px solid saddlebrown;" align="right">31</td><td style="border:1px solid saddlebrown;" align="right">1409</td><td style="border:1px solid saddlebrown;" align="right">1378</td><td style="border:1px solid saddlebrown;" align="right">1534</td><td style="border:1px solid saddlebrown;" align="right">1315</td><td style="border:1px solid saddlebrown;" align="right">126</td><td style="border:1px solid saddlebrown;" align="right">899</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">7-2013</td><td style="border:1px solid saddlebrown;" align="right">29</td><td style="border:1px solid saddlebrown;" align="right">1378</td><td style="border:1px solid saddlebrown;" align="right">1582</td><td style="border:1px solid saddlebrown;" align="right">1531</td><td style="border:1px solid saddlebrown;" align="right">1247</td><td style="border:1px solid saddlebrown;" align="right">0</td><td style="border:1px solid saddlebrown;" align="right">688</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">6-2013</td><td style="border:1px solid saddlebrown;" align="right">30</td><td style="border:1px solid saddlebrown;" align="right">1864</td><td style="border:1px solid saddlebrown;" align="right">2063</td><td style="border:1px solid saddlebrown;" align="right">2387</td><td style="border:1px solid saddlebrown;" align="right">2073</td><td style="border:1px solid saddlebrown;" align="right">0</td><td style="border:1px solid saddlebrown;" align="right">959</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">5-2013</td><td style="border:1px solid saddlebrown;" align="right">24</td><td style="border:1px solid saddlebrown;" align="right">1732</td><td style="border:1px solid saddlebrown;" align="right">1587</td><td style="border:1px solid saddlebrown;" align="right">2809</td><td style="border:1px solid saddlebrown;" align="right">1738</td><td style="border:1px solid saddlebrown;" align="right">0</td><td style="border:1px solid saddlebrown;" align="right">937</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">4-2013</td><td style="border:1px solid saddlebrown;" align="right">30</td><td style="border:1px solid saddlebrown;" align="right">2184</td><td style="border:1px solid saddlebrown;" align="right">2071</td><td style="border:1px solid saddlebrown;" align="right">2448</td><td style="border:1px solid saddlebrown;" align="right">2008</td><td style="border:1px solid saddlebrown;" align="right">0</td><td style="border:1px solid saddlebrown;" align="right">851</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">3-2013</td><td style="border:1px solid saddlebrown;" align="right">15</td><td style="border:1px solid saddlebrown;" align="right">1075</td><td style="border:1px solid saddlebrown;" align="right">1096</td><td style="border:1px solid saddlebrown;" align="right">1795</td><td style="border:1px solid saddlebrown;" align="right">1306</td><td style="border:1px solid saddlebrown;" align="right">0</td><td style="border:1px solid saddlebrown;" align="right">759</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">2-2013</td><td style="border:1px solid saddlebrown;" align="right">28</td><td style="border:1px solid saddlebrown;" align="right">2786</td><td style="border:1px solid saddlebrown;" align="right">2955</td><td style="border:1px solid saddlebrown;" align="right">2119</td><td style="border:1px solid saddlebrown;" align="right">2754</td><td style="border:1px solid saddlebrown;" align="right">0</td><td style="border:1px solid saddlebrown;" align="right">1673</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">1-2013</td><td style="border:1px solid saddlebrown;" align="right">22</td><td style="border:1px solid saddlebrown;" align="right">2831</td><td style="border:1px solid saddlebrown;" align="right">2261</td><td style="border:1px solid saddlebrown;" align="right">3278</td><td style="border:1px solid saddlebrown;" align="right">3404</td><td style="border:1px solid saddlebrown;" align="right">0</td><td style="border:1px solid saddlebrown;" align="right">2208</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">12-2012</td><td style="border:1px solid saddlebrown;" align="right">26</td><td style="border:1px solid saddlebrown;" align="right">3017</td><td style="border:1px solid saddlebrown;" align="right">3358</td><td style="border:1px solid saddlebrown;" align="right">3137</td><td style="border:1px solid saddlebrown;" align="right">3729</td><td style="border:1px solid saddlebrown;" align="right">0</td><td style="border:1px solid saddlebrown;" align="right">2639</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">11-2012</td><td style="border:1px solid saddlebrown;" align="right">30</td><td style="border:1px solid saddlebrown;" align="right">5156</td><td style="border:1px solid saddlebrown;" align="right">5015</td><td style="border:1px solid saddlebrown;" align="right">4955</td><td style="border:1px solid saddlebrown;" align="right">5099</td><td style="border:1px solid saddlebrown;" align="right">0</td><td style="border:1px solid saddlebrown;" align="right">3942</td></tr>
<tr><td style="border:1px solid saddlebrown;">BAKKEN</td><td style="border:1px solid saddlebrown;" align="right">10-2012</td><td style="border:1px solid saddlebrown;" align="right">30</td><td style="border:1px solid saddlebrown;" align="right">8127</td><td style="border:1px solid saddlebrown;" align="right">7743</td><td style="border:1px solid saddlebrown;" align="right">11322</td><td style="border:1px solid saddlebrown;" align="right">8267</td><td style="border:1px solid saddlebrown;" align="right">0</td><td style="border:1px solid saddlebrown;" align="right">7390</td></tr>
</table></div>

</td>
</tr>
</table>
<p align="center"><font size="-1">[<a href="/default.asp">DMR Home</a>] [<a href="/oilgas/disclaimer.asp">Disclaimer</a>] [<a href="/oilgas/privacy.asp">Privacy</a>] [<a href="/oilgas/security.asp">Security</a>] [<a href="/oilgas/feeservices/feedback.asp">Feedback</a>] [<a href="/oilgas/feeservices/myaccount.asp">My Account Information</a>]</font></p>
</body>

</html>

我已经能够使用上面的宏将表拉到excel中,但是我很难弄清楚如何创建一个循环,这个循环将多次重复此过程,给定一个标识符列表(附加到的数字) url的结尾),并为每个页面创建一个新的工作簿。

1 个答案:

答案 0 :(得分:0)

1 从长远来看,你应该考虑阅读一本书或关注Stack Overflow问题https://stackoverflow.com/questions/7523102/what-is-the-best-way-to-master-vba-macros-for-ms-office-applications中推荐的论坛

2 Excel VBA = Excel对象模型(砖块)+ Visual Basic for Applications(胶水)

为了成功操作Excel对象模型,您必须知道如何使用Visual Basic(创建循环,使用数组,连接字符串等)。

在许多&#34; Excel VBA教程中&#34;可用http://www.excel-easy.com/vba.html似乎可以提供快速介绍,http://www.angelfire.com/biz7/julian_s/julian/julians_macros.htm似乎提供了许多复制/粘贴就绪代码段

3 为了抓取更复杂的网络表格(例如,多页面,受密码保护,需要特殊按钮点击等),您可以找到Selenium浏览器自动化工具的有用VBA映射{ {3}}


在Visual Basic编辑器中按F1并将光标放在您需要解释的术语上也是非常快速的学习方式,因为Microsoft的官方Excel开发人员参考文档非常好