You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用VBA的QueryTables.Add将谷歌表格大数字以文本导入Excel?

问题:导入谷歌表格条码数据至Excel时保留完整数字格式

我需要通过VBA将包含条码信息的谷歌表格导入Excel,要求条码数字完全保留原样。尝试使用WebFormatting = xlNone无法阻止导入时覆盖目标单元格格式,最终数据以“常规”格式粘贴,导致长数字被Excel自动缩短(事后手动修改格式也无法恢复丢失的数字)。

谷歌表格地址:https://docs.google.com/spreadsheets/d/19z0-gYw645ns1V5nUwW5eUu0xwq5PJOu84TShSv8OPM/edit?usp=sharing

已尝试的两种方法

方法1:URL导入法

代码实现:

Sub Import_Data()

 Cells.Clear
 
 Dim conn As String
 Dim qt As QueryTable
 conn = "URL;https://docs.google.com/spreadsheets/d/19z0-gYw645ns1V5nUwW5eUu0xwq5PJOu84TShSv8OPM/edit?usp=sharing"
 Set qt = ActiveSheet.QueryTables.Add(Connection:=conn, Destination:=Range("$A$1"))
 
 With qt
        .WebTables = "1"
        .WebFormatting = xlNone
        .WebSelectionType = xlSpecifiedTables
        .Refresh
 End With
End Sub

结果:条码数字被缩短,丢失的数字无法通过后续格式修改恢复。

方法2:TEXT导入法

代码实现:

Sub Import_Data_As_Text()

 Cells.Clear

    With ActiveSheet.QueryTables.Add(Connection:="TEXT;https://docs.google.com/spreadsheets/d/19z0-gYw645ns1V5nUwW5eUu0xwq5PJOu84TShSv8OPM/edit?usp=sharing", Destination:=Range("$A$1"))
    
    
    .TextFileCommaDelimiter = True
    .FieldNames = False
    .RowNumbers = True
    .FillAdjacentFormulas = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlOverwriteCells
    .SavePassword = False
    .SaveData = False
    .AdjustColumnWidth = True
    .TextFileColumnDataTypes = _
 Array(xlDMYFormat, xlTextFormat)
    .Refresh BackgroundQuery:=False

   End With
End Sub

结果:导入内容混乱,甚至加载出网页代码,条码列内容不完整。

恳请提供可行的解决思路,谢谢!


内容的提问来源于stack exchange,提问作者Dimokratis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 05:50:37