Macro Command To Check For Open Workbook

MikeG

Well-known Member
Joined
Jul 4, 2004
Messages
845
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a macro below that copies a worksheet to a new workbook and then saves that new workbook.

The macro runs fine, except if a workbook with the same name as the new workbook is trying to use is open. Then the macro halts with an error: "You cannot save this workbook with the same name as another open workbook..."

Could someone give me some code that will alert the user with the same message, but will not end the macro with the VB End Debug message. i.e. I would like to display the message and then just terminate the macro "legally".

Here is the macro:


========================================
Dim wbNew As Workbook, wbCur As Workbook

Set wbCur = ActiveWorkbook
ThisWorkbook.Worksheets("EIS Setup Worksheet").Copy

Set wbNew = ActiveWorkbook
With wbNew
.SaveAs Filename:=Range("Save_Name2") & ".xlsx"

End With

==========================================


Thanks,

Mikeg
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,224,617
Messages
6,179,915
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top