vb.net - 按索引激活工作表

标签 vb.net excel

我有一个带有前进和后退按钮的 winform。我想要做的是允许用户通过单击按钮在工作簿上来回移动。我认为实现这一目标的最佳方法是使用 index.html 。然而,它让我很适应。 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()

关于vb.net - 按索引激活工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17690072/

相关文章:

asp.net - 我必须将 CausesValidation ="False"添加到每个 ASP 按钮才能工作,为什么?

c# - 有谁知道用于处理数量/度量单位对的库?

javascript - 单击asp图像按钮时如何避免回发?

excel - 我如何获取单元格的列字母(需要使其在 Z 列之后工作,例如 AA、AB)

excel - 如何在 Excel 中使用数据透视表计算一个单元格中的多个值?

excel - 如何测试 Excel VBA 范围变量对整个列的引用?

MySQL DataConnections 未关闭/合并

xml - 关于 VB NET 中 XML 摘要注释的问题

swift - 在 Swift Xcode 中使用 Excel 工作表中的数据

excel - 如何根据条件复制值并将其粘贴到另一个工作表