macro forbid to replace the file

flamme20

New Member
Joined
Apr 27, 2011
Messages
31
I'd like to know if there's a macro I can add into excel sheet which would forbid to replace the file and forbid changes in a certain range?
I'd be grateful if anyone can give me an advice.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
What do you mean by "replace the file"?

If you format a range of cells as Locked and then Protect the worksheet with a password, that will stop people modifying that range of cells.

A macro is only of use if the person enables macros when they open the workbook.
 
Upvote 0
What do you mean by "replace the file"?

If you format a range of cells as Locked and then Protect the worksheet with a password, that will stop people modifying that range of cells.

A macro is only of use if the person enables macros when they open the workbook.

By "replace the file" I mean that this one is an All Users file. Sometimes it happens that one person who's working with it copies this file to his pc, modifies it and pastes it back; at this time I make modifications by network. I finish and save while the other person replaces the already modified file by his own.
 
Upvote 0
You can include some code which will cause the workbook to immediately close if anyone tries to open it from a different location but this will only work if they enable macros when they open it.
Code:
[FONT=Fixedsys][COLOR=black]Private Sub Workbook_Open()[/COLOR][/FONT]
[FONT=Fixedsys][COLOR=black][/COLOR][/FONT] 
[FONT=Fixedsys][COLOR=black]  If ThisWorkbook.FullName <> "[/COLOR][/FONT][URL="file://\\servername\sharename$\workbookname.xlsm"][FONT=Fixedsys][COLOR=black]\\servername\sharename$\workbookname.xlsm[/COLOR][/FONT][/URL][FONT=Fixedsys][COLOR=black]" Then
    ThisWorkbook.Close SaveChanges:=False
  End If
  
End Sub
[/COLOR][/FONT]
This is easily defeated by holding the Shift key down when the workbook opens and you can't even issue a warning MsgBox because that will give the user the opportunity of hitting Ctrl-Break and aborting the code.
 
Upvote 0

Forum statistics

Threads
1,224,537
Messages
6,179,405
Members
452,911
Latest member
a_barila

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