I need to determine if a workbook is already open. If it is already open, my code is generating an error.
I am copying a sheet from one workbook to another. If the source workbook is already open, it fails.
If the source workbook is already open, I want to display a message to the user "Workbook sourceworkbook is already open"
Here's what I have...it works great if sourceworkbook is not already open
RQTReport = Application.GetOpenFilename(, , "Browse for IPS / RQT Quotation") 'select a workbook to open
If RQTReport = "False" Then Exit Sub 'exit if user selects Cancel
Set currentworkbook = ThisWorkbook
Set sourceworkbook = Workbooks.Open(RQTReport)
sourceworkbook.Activate
For i = 1 To Worksheets.Count
If Worksheets(i).Name = "Export" Then 'from RQT 'check to see if any of the source workbook sheets are named Export
sourceworkbook.Sheets("Export").Copy before:=currentworkbook.Sheets("QuoteTemplate") 'THIS IS THE LINE THAT ERRORS IF THE WORKBOOK IS ALREADY OPEN
End If
Next i
I am copying a sheet from one workbook to another. If the source workbook is already open, it fails.
If the source workbook is already open, I want to display a message to the user "Workbook sourceworkbook is already open"
Here's what I have...it works great if sourceworkbook is not already open
RQTReport = Application.GetOpenFilename(, , "Browse for IPS / RQT Quotation") 'select a workbook to open
If RQTReport = "False" Then Exit Sub 'exit if user selects Cancel
Set currentworkbook = ThisWorkbook
Set sourceworkbook = Workbooks.Open(RQTReport)
sourceworkbook.Activate
For i = 1 To Worksheets.Count
If Worksheets(i).Name = "Export" Then 'from RQT 'check to see if any of the source workbook sheets are named Export
sourceworkbook.Sheets("Export").Copy before:=currentworkbook.Sheets("QuoteTemplate") 'THIS IS THE LINE THAT ERRORS IF THE WORKBOOK IS ALREADY OPEN
End If
Next i