我将我的excel vb代码复制到vbs中,我知道存在语义/逻辑差异,非常感谢一些指导。我收到的错误是“ Next i ”(第44行) - 这实际上是一个整数。
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
答案 0 :(得分:0)
Next
关闭for
循环。但是你没有任何for循环。删除两行next
。
EG和以前一样,除了作为变体之外,你不能声明任何东西,省略as type
。你只是不考虑类型。
Public Function ZeroToBlank(x)
If x = "0" Then
ZeroToBlank = ""
Else
ZeroToBlank = x
End If
End Function