【问题标题】:VBA - Query Table - Getting data from google sheetVBA - 查询表 - 从谷歌表中获取数据
【发布时间】:2020-06-10 20:30:00
【问题描述】:

我有一个功能,主要是在网上找到的,从 Google 表格中获取表格

Sub GetDataFromGoogle(wsn As String, address As String)
Dim i As Integer
  With Worksheets(wsn)
    With .QueryTables.Add(Connection:="URL;" & address, Destination:=.Range("$A$1"))
        .PreserveFormatting = False
        .BackgroundQuery = True
        .WebFormatting = xlWebFormattingNone
        .Refresh BackgroundQuery:=False
    End With
    DoEvents
  End With
    For i = 1 To ThisWorkbook.Connections.Count
        If ThisWorkbook.Connections.Count = 0 Then Exit Sub
        ThisWorkbook.Connections.item(i).Delete
    i = i - 1
    Next i
End Sub

它似乎工作得很好,但是当我开发我的数据库时,发生了一个问题。

我只得到了我的谷歌表的前 100 个条目,然后我得到了一个空行,第一个下一个范围上有一个奇怪的文本,然后在位置 3 下的行是单词 @987654322 @

我不知道它是什么。

【问题讨论】:

  • “一个奇怪的文字”——它看起来像什么?它是否对应于您的 Google 表格中的某些特定行?
  • 它根本不在我的工作表中。我以前从未见过这样的文字:Les cours des actions ne couvrent pas toutes les places boursières et peuvent être différés d'une durée allant jusqu'à 20 minutes. Les chiffres sont fournis "en l'état", à titre d'information uniquement, et non à des fins commerciales ou de conseils. Clause de non-responsabilité。它始终是相同的文本。

标签: excel vba google-sheets


【解决方案1】:

Sub Uygula()
 Sheets("Veri").Range("A1:D600").ClearContents
 Call GetDataFromGoogle("Veri", "18I8Vddjir3lFvtUorMln4mXlYNsY0KZtBGywVreped4")
End Sub

Sub GetDataFromGoogle(wsn As String, adres As String)
Dim i As Integer
Dim qry As String
Dim myURL As String
    qry = Application.EncodeURL("SELECT A, C, G, B")
    myURL = "https://docs.google.com/spreadsheets/d/" & adres & "/gviz/tq?tqx=out:csv&sheet=1&tq=" & qry

With Worksheets(wsn)
With .QueryTables.Add(Connection:="TEXT;" & myURL, Destination:=.Range("$A$1"))
     .Name = "myTable"
     .TextFilePlatform = 65001
     .SaveData = False
     .AdjustColumnWidth = True
     .RefreshPeriod = 0
     .TextFileStartRow = 1
     .TextFileParseType = xlDelimited
     .TextFileCommaDelimiter = True
     .TextFileSpaceDelimiter = False
     .Refresh BackgroundQuery:=False
End With
'DoEvents
End With
'For i = 1 To ThisWorkbook.Connections.Count
'If ThisWorkbook.Connections.Count = 0 Then Exit Sub
'ThisWorkbook.Connections.Item(i).Delete
'i = i - 1
'Next i
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    相关资源
    最近更新 更多