我是编程新手,显然对编写函数不是很有经验。我在下面编写了函数,但是当我走到最后时,End Function 语句有一个错误:函数“viewSheets”没有在所有代码路径上返回值。
我已经研究过这个问题,但无济于事。这是我第一次尝试一个函数:
Option Strict On
Option Explicit On
Imports Microsoft.Office.Interop.Excel
Imports System.Windows.Forms
Module sheetView
Function viewSheets(sheetName As String, status As Boolean, show As String) As String
Dim ThisApplication As Excel.Application = New Excel.Application()
Dim WB As Excel._Workbook
Dim WS As Excel.Worksheet
WB = CType(Globals.ThisWorkbook.Application.ActiveWorkbook, Excel.Workbook)
WS = DirectCast(WB.Sheets("sheetName"), Excel.Worksheet)
With ThisApplication
.ScreenUpdating = False
WS.Select()
.ActiveWindow.DisplayGridlines = status
.ActiveWindow.DisplayHeadings = status
.ActiveWindow.DisplayWorkbookTabs = status
.DisplayFormulaBar = status
.DisplayStatusBar = status
.ExecuteExcel4Macro("Show.ToolBar(""Ribbon"", show )")
.ScreenUpdating = True
End With
End Function
端模块