Dzwebs.Net

撰写电脑技术杂文十余年

vba把网页数据导入到Excel中

Admin | 2012-11-21 10:07:36 | 被阅次数 | 11212

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

  以下的VBA代码,其功能是将网页导入到Excel里面,下面是相关的代码。

  MyPath = "D:\MyPage.html"
  Workbooks.Add
  With ActiveSheet.QueryTables.Add(Connection:="FINDER;" & MyPath, Destination:=Range("A1"))
          .Name = "Top"
          .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

  下面的代码是导入指定位置的网页数据

     With ActiveSheet.QueryTables.Add(Connection:= _
          "FINDER;file:///E:/MyPage.htm", Destination:=Range("A1"))
          .Name = "Top"
          .FieldNames = True
          .RowNumbers = False
          .FillAdjacentFormulas = False
          .PreserveFormatting = True
          .RefreshOnFileOpen = False
          .BackgroundQuery = True
          .RefreshStyle = xlInsertDeleteCells
          .SavePassword = False
          .SaveData = True
          .AdjustColumnWidth = True
          .RefreshPeriod = 0
          .WebSelectionType = xlEntirePage
          .WebFormatting = xlWebFormattingNone
          .WebPreFormattedTextToColumns = True
          .WebConsecutiveDelimitersAsOne = True
          .WebSingleBlockTextImport = False
          .WebDisableDateRecognition = False
          .WebDisableRedirections = False
          .Refresh BackgroundQuery:=False
      End With


该杂文来自: Excel杂文

上一篇:excel里面的宏无法使用

下一篇:vba PivotFields方法使用介绍

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计