运行时错误1004:数据源初始化失败(32位和64位Excel版本之间的问题)

时间:2017-04-17 12:38:50

标签: excel vba runtime 32bit-64bit oledbconnection

我有这个代码(不是我写的),它总是很好用于它的目的。由于我的Office版本已从2010 32位升级到2016 64位,因此它停止工作,导致运行时错误1004:数据源初始化失败。我在拥有32位版Excel 2016的计算机上进行了测试,它运行良好!由于我不熟悉查询表,我无法找到它发生的原因。有人可以给我一个灯吗?我在互联网上发现了类似的问题,但无法解决目标解决方案的问题。

这是代码。它停在“.Refresh BackgroundQuery:= False”:

Sub Importar_Prime()
    Sheets("Estoque Polo").Select
    Cells.Select
    Selection.ClearContents
    Selection.QueryTable.Delete
    Selection.End(xlUp).Select
    With ActiveSheet.QueryTables.Add(Connection:=Array( _
        "OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\temp\esce014.xls;Mode=Share Deny Write;Extended Proper" _
        , _
        "ties=""HDR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=35;" _
        , _
        "Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Databas" _
        , _
        "e Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=Fal" _
        , "se;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False"), _
        Destination:=Range("A1"))
        .CommandType = xlCmdTable
        .CommandText = Array("Plan1$")
        .Name = "esce014_1"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .SourceDataFile = "C:\temp\esce014.xls"
        .Refresh BackgroundQuery:=False
    End With
    Rows("1:7").Select
    Selection.Delete Shift:=xlUp
    Range("A1").Select
    Cells.Replace What:="_", Replacement:="", LookAt:=xlPart, SearchOrder:= _
        xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    Cells.Select
    Cells.EntireColumn.AutoFit
    Cells.Select
    Selection.NumberFormat = "General"
    Columns("F:F").Select
    Selection.Delete Shift:=xlToLeft
    Columns("G:H").Select
    Selection.Delete Shift:=xlToLeft
    Columns("K:K").Select
    Selection.Insert Shift:=xlToRight
    Range("P1").Select
    ActiveCell.FormulaR1C1 = "=IF(RC1="""",""ZZZ"",RC[-12])"
    Range("P1").Select
    Selection.Copy
    Range("Q1").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Range("P1:Q1").Select
    Selection.Copy
    Application.Goto Reference:="R3000C16"
    Range(Selection, Selection.End(xlUp)).Select
    Range("P1:Q3000").Select
    Range("P3000").Activate
    ActiveSheet.Paste
    Selection.End(xlUp).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range("P1:Q3000").Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Columns("P:P").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("D:D").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Columns("Q:Q").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("E:E").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Columns("P:Q").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Selection.End(xlToLeft).Select
    Selection.End(xlToLeft).Select
    Selection.End(xlToLeft).Select
    Selection.End(xlToLeft).Select
    Selection.End(xlToLeft).Select
    Cells.Replace What:="ZZZ", Replacement:="", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    Sheets("Relatório").Select
End Sub

0 个答案:

没有答案