我有一张Excel表格,我希望将其作为Google表格的备份,我会定期清理,以防止它减速。我正在尝试编写一个宏,在一段时间后,将在Excel工作表中找到下一个空行,激活“A”列中的单元格,然后从Google工作表中导入数据。我不想在Excel中“刷新”数据,因为计划是每隔一段时间删除Google表格中的数据,而Excel表格作为连续记录。我只想将当前的Google Sheet数据拉入下一个空行的第一个单元格,并安排重复。
以下是我一直在尝试的内容:
Sub addData()
newCell = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Address
MsgBox newCell
Sheet1.QueryTables.Add(Connection:= _
"URL;googleSheetURL" _
, Destination:=Range(newCell))
.PostText = "transaction-data_1"
.Name = False
.FieldNames = False
.RefreshStyle = xlInsertDeleteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.HasAutoFormat = False
.RefreshOnFileOpen = 2
.BackgroundQuery = False
.TablesOnlyFromHTML = True
.SaveData = True
.Refresh BackgroundQuery:=False
.UseListObject = False
End With
End Sub
将googleSheetURL
替换为工作表的已发布链接。
我只是不断收到错误,调试模式突出显示Refresh BackgroundQuery
行。我禁用了后台刷新,因为我不想在我拉它们后更新查询。有没有人有任何见解?
答案 0 :(得分:-1)
此代码无法编译。您在With
前面错过了Sheet1
:
Sub addData()
newCell = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Address
With Sheet1.QueryTables.Add(Connection:= _
"URL;googleSheetURL" _
, Destination:=Range(newCell))
.PostText = "transaction-data_1"
.Name = False
.FieldNames = False
.RefreshStyle = xlInsertDeleteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.HasAutoFormat = False
.RefreshOnFileOpen = 2
.BackgroundQuery = False
.TablesOnlyFromHTML = True
.SaveData = True
.Refresh BackgroundQuery:=False
.UseListObject = False
End With
End Sub