0
我創建了一個用戶窗體frmNavigation
,它具有一個ListBox1
,它將列出工作簿中的所有工作表,並且可以雙擊任何工作表列表框並轉到該表單。在excel vba用戶窗體中創建一個後退按鈕,轉到上一個活動窗體
現在,因爲我有近50個工作表,所以我從出現在ListBox1
的列表中雙擊並轉到該工作表,但現在我想要一個後退按鈕「CommandButton2」,以便它可以將我帶回到先前的活動工作表。
我已經創建了一個代碼,但它不工作。
Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
Dim i As Integer, Sht As String
'for loop
For i = 0 To ListBox1.ListCount - 1
'get the name of the selected sheet
If ListBox1.Selected(i) = True Then
Sht = ListBox1.List(i - 1)
End If
Next i
'select the sheet
Sheets(Sht).Select
'reset the userform
Unload Me
frmNavigation.Show
End Sub
它給我的錯誤爲下標超出範圍就行表(LastSelectedSht)。選擇 – astha
私人小組UserForm_Initialize() 昏暗SH作爲變 「每個循環的新增可見片 對於每個sh放在ActiveWorkbook.Sheets 「添加片材到列表框 Me.ListBox1.AddItem Sh.Name 接着噓 – astha
@astha什麼時候?你第一次加載你的表單? –