2012-06-06 81 views
0

我有一個初始化事件用戶窗體如下:初始化與VBA用戶窗體和加載變量在Excel

Public CurrSpanNum, CurrSegNum As Integer 
Private Sub UserForm_Initialize() 

     CurrSegNum = Sheets("UserData").Range("C2").value 
     Debug.Print "SegForm, SpanNum = " & CurrSpanNum 
     CurrSpanNum = Sheets("UserData").Range("D2").value 
     Debug.Print "SegForm, SegNum = " & CurrSegNum 

End Sub 

在立即窗口我看到:

SegForm, SpanNum = 
SegForm, SegNum = 3 

值3被放置在表單初始化之前的兩個單元格中。爲什麼我似乎無法加載SpanNum,而SegNum能夠加載?

回答

3

那麼,你的CurrSpanNum變量沒有初始化,所以什麼也不打印,你會期望什麼?

+0

拍!我覺得今天早上咖啡壞了... – Ehudz