title: Stop Macro and close workbook if opened as read only?
body: <p>I've worked out a macro that will open a couple of other workbooks, refresh the data and then save and close. However, the books being opened may sometimes be in use by another department if they are adding data. Is there a way to have the macro terminate and close the workbook if it is opened as read only?</p>
  
  <p>The problem is that the macro encounters a read only error when trying to save.</p>
  
  <pre><code>Sub Refresh_All()
  '
  ' Refresh_All Macro
  '
  ' Keyboard Shortcut: Ctrl+Y
  '
      ChDir "Q:\Quality Control"
      Workbooks.Open Filename:= _
          "Q:\Quality Control\Internal Failure Log - Variable Month.xlsm"
      Dim endTime As Date
      endTime = DateAdd("s", 10, Now())
      Do While Now() &lt; endTime
  DoEvents
      Loop
      ActiveWorkbook.RefreshAll
         endTime = DateAdd("s", 10, Now())
      Do While Now() &lt; endTime
          DoEvents
      Loop
  ActiveWorkbook.Save
      endTime = DateAdd("s", 5, Now())
      Do While Now() &lt; endTime
          DoEvents
      Loop
      ActiveWindow.Close
      ChDir "Q:\Reports"
      Workbooks.Open Filename:= _
          "Q:\Reports\Finished-Transfer Report-variable month.xlsm"
          endTime = DateAdd("s", 10, Now())
      Do While Now() &lt; endTime
          DoEvents
      Loop
  ActiveWorkbook.RefreshAll
       endTime = DateAdd("s", 10, Now())
      Do While Now() &lt; endTime
          DoEvents
      Loop
  ActiveWorkbook.Save
          endTime = DateAdd("s", 5, Now())
      Do While Now() &lt; endTime
          DoEvents
      Loop
  ActiveWindow.Close
      ActiveWorkbook.RefreshAll
          endTime = DateAdd("s", 10, Now())
      Do While Now() &lt; endTime
          DoEvents
      Loop
  ActiveWorkbook.Save
  End Sub
  </code></pre>