首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

VBA 全局变量的有关问题

2012-03-04 
VBA 全局变量的问题OnB 是 B 的回调函数,我是想定义一个全局变量rowIndex,然后在OnB被调用时用到这个值,报

VBA 全局变量的问题
OnB 是 B 的回调函数,我是想定义一个全局变量rowIndex,然后在OnB被调用时用到这个值,
报错出在rowIndex=2这句话了,有人知道为什么吗,刚刚接触VBA

VB code
Option ExplicitDim WithEvents CSSS As BAPI;Dim tradeSheet As WorksheetDim tradeRow As LongPublic rowIndex As IntegerrowIndex = 2Private Sub CommandButton1_Click()    Dim ErrorID As Long    Set tradeSheet = ThisWorkbook.Sheets("trade_record")    tradeRow = 4    If CSSS Is Nothing Then       Set CSSS = New COMLIB.BAPI    End If        Dim frm As UserForm1        Set frm = New UserForm1        frm.Show        If Len(frm.txtUserName) > 0 Then            Call CSSS.Login(frm.txtUserName.Value, frm.txtPassword.Value, ErrorID)            If ErrorID <> 0 Then                MsgBox "Failed to Login, ErrorID:" & ErrorID                Set ctp = Nothing            End If        End IfEnd SubPrivate Sub CommandButton2_Click()    Call CSSS.CloseEnd Sub'when com finished initialized;Private Sub OnConnected()    Dim str As String    str = "xxxxx"    Call B(str)End SubPrivate Sub OnB()     Cells(rowIndex, 1).Value = "XX"     'rowIndex = rowIndex + 1End Sub


[解决办法]
VB code
Private Sub Document_Open()    rowIndex = 2End Sub 

热点排行