有关通过 VBA 导入谷歌表格以 excel 的问题



我是 VBA 的新手,我最近收到一个请求,要求我创建一个按钮,将数据从谷歌表格导入到 excel 表格。我已经尝试了在互联网上找到的方法并取得了一些进展。但是关于 VBA 的Microsoft文档非常模糊,因此我认为最好在这里提出问题。

我使用这段代码导入数据:

With ActiveSheet.QueryTables.Add("URL;" & googleURL, Destination:=Range("$A$1"))
.WebTables = "1"
.Refresh False
End With

问题:

  1. 这段代码最多只能从 google 工作表表中导入 100 行数据。问题是否有原因或解决方法?

  2. 有没有办法修改结果,使其不包含列标题和行号单元格(例如:A、B、1、2、3(?如果没有,有没有办法在刷新后删除它们?

  3. 有没有办法从谷歌工作表中获取特定的单元格(例如:D5(并将其放在 excel 工作表上?

  4. 如果我先阅读谷歌表格并将其保存在文件中,然后按照我喜欢的方式修改或阅读它会更容易吗?

希望有人可以帮助我,我非常感谢您阅读我的问题!

您没有提供测试链接,但我怀疑通用 Web 查询会为您完成这项工作。打开宏录制器并从 Web 导入电子表格数据,就像任何其他类似任务一样。

Sub Basic_Web_Query()
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;https://docs.google.com/spreadsheet/ccc?key=0Ah4Bis8FTYfCdDJILVdYOG1EZEYtc1N3NF96dHZSYkE&usp=sharing#gid=0", Destination:=Range("$A$1"))
.Name = "q?s=goog_2"
.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,2"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub

最新更新