title: Power Query OnEvent based scripting
body: <p>I'm having an issue with two things relating to PowerQuery in Excel 2016.  The first is that when I do a refresh in VBA the code doesn't stop for a DB connection error message, even without an On Error Resume Next type of line.  I would like for the user to know when there is a connection is, and more importantly for the script to Go To another line and bypass some code should one occur</p>
  
  <p>The second issue is closely related to the first, I would like to notate a specific (named) cell with a date/time stamp of when the last refresh took place.  </p>
  
  <p>Note: This workbook has 4 Power Query loaded tables in it (created from appx 15 DB SQL Server DB queries through PwrQry).</p>
  
  <p>This is the current code I have for a refresh all and timestamp</p>
  
  <pre><code>Sub RefreshALLdata()
  
  'On Error GoTo Err
  
  ThisWorkbook.RefreshAll
  
  ActiveSheet.Unprotect
  
  With Range("RefreshAllDateTime")
      .Value = Now()
      .NumberFormat = "mm/dd/yyyy h:mm:ss AM/PM"
  End With
  
  'Err:
  
  ActiveSheet.Protect
  
  End Sub
  </code></pre>
  
  <p>When a friend of mine (Who doesn't have DB access) uses this code, it skips right past the failed connection message and adds the DataTime stamp regardless.  I tried with and then without the OnError coding to see if the error would pop up, but it doesn't even error out at all.</p>
  
  <p>I'm hoping to create individual buttons for each page afterwards with a script that does a refresh of the listobject on current page and adds a timestamp for each table, but haven't gotten there yet.</p>
  
  <p>Any guidance with regard to this matter would be very appreciated!</p>
  
  <p>Thank you in advance!</p>
  
  <p>Sincerely,
  Kris </p>