Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

excel - Problem: When I run macro I receive unexpected error message

Here is the code.

    Sub Macro1()
'
' Macro1 Macro
'

'
     Let x = 0
    Do While x < 2
    Range("A" & Rows.Count).End(xlUp).Offset(1).Select
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
        "ODBC;DSN=CyclesDB;UID=tim;;SERVER=10.10.20.160;DATABASE=factorywiz;PORT=3306;" _
        , Destination:=ActiveCell).QueryTable
        '.CommandType = 0
        .CommandText = Array( _
        "SELECT realtimestate_0.RTCnc, realtimestate_0.RTTool, realtimestate_0.RTSpindleLoad" & Chr(13) & "" & Chr(10) & "FROM factorywiz.realtimestate " _
        , "realtimestate_0" & Chr(13) & "" & Chr(10) & "WHERE (realtimestate_0.RTCnc='Body 8 Kit 4')")
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .SourceConnectionFile = _
        "C:UsersespoorsDocumentsMy Data SourcesQuery from CyclesDB6.odc"
        '.ListObject.DisplayName = "Table_Query_from_CyclesDB6_1"
         .Refresh BackgroundQuery:=False
    End With
    x = x + 1
    Loop
End Sub

Here is the error information.enter image description here

I don't know what more details you need. I am trying to import data from ODBC connector and keep getting this error please help.

question from:https://stackoverflow.com/questions/65905805/problem-when-i-run-macro-i-receive-unexpected-error-message

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...