Stop Workbook opening if already open

uk747

Well-known Member
Joined
Jul 20, 2011
Messages
843
Office Version
  1. 365
Platform
  1. Windows
I have a macro which when run copies information from one sheet to another.

What i need is when one person is running the macro and their information is being transferred to the database workbook, the 2nd or 3rd or 4th etc who is transferring gets a message which says workbook currently in use please try again. then they keep pressing the macro till it eventually transfers successfully :)


Code:
Application.ScreenUpdating = False
 
 
NewName = ActiveWorkbook.Name
 
Workbooks.Open "S:\Workbook2.xls"
 
If ActiveWorkbook.ReadOnly = True Then
MsgBox "The database is being accessed by another user. Please ty again"
ActiveWindow.Close
Exit Sub
Else
 
'Copy information from Workbook1 
Workbooks(NewName).Sheets("Transfer").Range("A1001:D1001").Copy
Workbooks("Workbook2.xls").Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
Workbooks("Workbook2.xls").Sheets("Sheet2").Range("A2:I5").Copy
Workbooks(NewName).Sheets("Transfer").Range("A1005").PasteSpecial Paste:=xlPasteValues
 
 
'Save and close YTD Spreadsheet
 
ActiveWorkbook.Save
ActiveWindow.Close
 
Workbooks(NewName).Activate
CutCopyMode = False
ThisWorkbook.Activate
Sheets("Transfer").Select
 
Range("B6").Select
Selection.ClearContents
 
 
 
End If
MsgBox "Thankyou. The data you submitted has been saved sucessfully.", vbInformation, "Saved Data"
 
 
Application.ScreenUpdating = True
 
End Sub


Ive tried Application.DisplayAlerts = False and Application.DisplayAlerts = True <!-- / message --><!-- sig -->

but cant get it to work properly.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,224,550
Messages
6,179,459
Members
452,915
Latest member
hannnahheileen

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