title: VBA IF NOT [function] then [code] runs code regardless of function output
body: <p>I wrote the following code:</p>
  <pre><code>Sub iojh()
  
  If Not foo() Then MsgBox (&quot;hi&quot;)
  
  End Sub
  
  Function foo() As Integer
  foo = 0
  End Function
  </code></pre>
  <p>It shows the msgbox when foo = 0 and when foo = 1. Why is this? I found a workaround using an If Else statement, but I'd like to know what's going on and if there's a better solution. This is my workaround:</p>
  <pre><code>Sub iojh()
  
  If foo() Then
      '
  Else
      MsgBox (&quot;hi&quot;)
  End If
  
  End Sub
  
  Function foo() As Integer
  foo = 1
  End Function
  </code></pre>