简体   繁体   中英

800A0401 vbs error

I copied my excel vb code into a vbs and I know there are semantic/logic differences, would really appreciate some guidance. I'm getting the error above for " Next i " (line 44) - which is essentially an integer.

Set xlBook = GetObject("C:\Users\midi\Desktop\IT\E\PRF.xlsm")
   For each wsheet in xlbook.worksheets
   msgbox wsheet.name

next

Sub RefreshConns()
    ' Refreshes the connections according to the specified cells

With Application
    .EnableEvents = False
    .ScreenUpdating = False
End With
Sheets("Run Macro").Activate
Dim connName 
Dim connStr 
Dim sqltext ' SQL text

Dim TempconnName 
Dim TempconnStr 
Dim Tempsqltext ' temporary SQL text
Dim i 
Dim SiteName 

SiteName = ActiveSheet.Cells(1, 2)
'MsgBox (SiteName)
For i = 5 To 11
connName = ActiveSheet.Cells(i, 1).Value
connStr = ActiveSheet.Cells(i, 2).Value
sqltext = ActiveSheet.Cells(i, 4).Value
'MsgBox (connName)

TempconnStr = Replace(connStr, "SiteNameVBA", SiteName)
'Debug.Print (ActiveWorkbook.Connections(connName).ODBCConnection.Connection)
'MsgBox (TempconnStr)
'Tempsqltext = Replace(sqltext, "SiteNameVBA", SiteName)

'On Error Resume Next
ActiveWorkbook.Connections(connName).ODBCConnection.CommandText = sqltext
ActiveWorkbook.Connections(connName).ODBCConnection.Connection = "ODBC;" & TempconnStr
ActiveWorkbook.Connections(connName).Refresh

Next i

With Application
    .EnableEvents = True
    .ScreenUpdating = True
End With

End Sub

Public Function ZeroToBlank(x String) String
If x = "0" Then
    ZeroToBlank = ""
Else
    ZeroToBlank = x
End If
End Function

Next closes a for loop. But you don't have any for loops. Delete both lines with next on them.

EG As before you can't declare anything except as variant which is done by omitting the as type . You just don't think about type.

Public Function ZeroToBlank(x)
    If x = "0" Then
        ZeroToBlank = ""
    Else
        ZeroToBlank = x
    End If
End Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM