我是編程新手,顯然對寫函數不太熟練。我寫了下面的函數,但隨着我到最後,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
前端模塊
其實,如果你不打算回來從你的函數的值,我只想讓一個子程序(方法),它不需要return語句 –