对于Next循环错误:Option Strict On禁止后期循环错误

时间:2017-01-10 16:48:06

标签: vb.net excel-interop

我有以下代码产生错误:

Option Strict On
Imports Microsoft.Office.Interop

Public Class Form1
Dim xlApp As New Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    xlWorkBook = xlApp.Workbooks.Open("C:\Book1.xlsx")
    xlApp.Visible = True
    For i = 1 To xlWorkBook.Worksheets.Count
        xlWorkBook.Worksheets(i).Visible = True
    Next
End Sub
End Class

谢谢。

1 个答案:

答案 0 :(得分:0)

我猜你所追求的是:

jqbs(".accordion-toggle" ).click(function() {
    if (jqbs('.arrow', this).attr('src') === "arrow-up") { //this panel is already open
      jqbs('.arrow', this).attr('src', '/arrow-down'); //show down arrow (for closed panels)
    }
    else { //open this panel
      jqbs('.arrow').attr('src', '/arrow-down'); //make them all look closed
      jqbs('.arrow', this).attr('src', '/arrow-up'); //make this one look open
    }
});

您应该始终考虑使用该对象,因为这将提供对象属性的正确用法。请注意Dim xlApp As New Excel.Application Dim xlWorkBook As Excel.Workbook Dim xlWorkSheet As Excel.Worksheet Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click xlWorkBook = xlApp.Workbooks.Open("C:\Book1.xlsx") xlApp.Visible = True For i = 1 To xlWorkBook.Worksheets.Count xlWorkSheet = CType(xlWorkBook.Worksheets(i), Excel.Worksheet) xlWorkSheet.Visible = Excel.XlSheetVisibility.xlSheetVisible 'If you don't want to make use of xlWorkSheet you can use this: 'CType(xlWorkBook.Sheets(i), Excel.Worksheet).Visible = Excel.XlSheetVisibility.xlSheetHidden Next End Sub Visible = True

的更改