title: Function error: Function doesn't return a value on all code paths
body: <p>I am new to programming and obviously not very experienced with writing functions. I wrote the function below, but as I get to the end, the End Function statements has an error: Function "viewSheets" doesn't return a value on all code paths.</p>
  
  <p>I have researched the issue, but to no avail.  Here is my first try at a function:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>End Module</p>