進むボタンと戻るボタンを備えたwinformがあります。私がやろうとしているのは、ユーザーがボタンをクリックしてワークブックを前後に移動できるようにすることです。これを達成する最善の方法は、インデックスを使用することだと思いました。しかし、それは私にフィット感を与えています。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