通过索引激活工作表

我有一个向前和向后的button的winform。 我想要做的是让用户通过点击button在工作簿上来回移动。 我认为实现这个最好的方法是使用索引。 但是,这是给我适合。 IDE告诉我,我在线上有语法错误:

(WS.Index - 1).Activate() 

 If Err.Number <> 0 Then WS(1).Activate() 

这是我的整个代码:

  Option Explicit On Option Strict On 'Import Libraries Imports Microsoft.Office.Tools.Excel Imports System.Drawing Imports System Imports System.IO Imports System.Drawing.Printing Imports System.Windows.Forms Public Class frmNavigation Dim WB As Excel.Workbook Dim WS As Excel.Worksheet Private Sub btnMoveBack_Click(sender As Object, e As EventArgs) Handles btnMoveBack.Click 'This event is triggered when the Previous Sheet button is 'clicked. The sheet moves to the previous sheet. This event 'is only run throughout the clientworksheets as the tabs and other 'standard excel navigation may be disabled. WB = CType(Globals.ThisWorkbook.Application.ActiveWorkbook, Excel.Workbook) WS = CType(WB.ActiveSheet, Excel.Worksheet) WS.Application.ScreenUpdating = False On Error Resume Next (WS.Index - 1).Activate() If Err.Number <> 0 Then WS(1).Activate() 'If error stay in the active sheet WS.Application.ScreenUpdating = True End Sub 

我认为这应该是:

 WB.WorkSheets(WS.Index -1).Activate() 

而不是仅仅

 (WS.Index -1).Activate()