LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Ultimate Control

I have a file that is set up so that on Before Save if it will cancel
and tell the user that you cannot save this file to another location if
the user attempted a Save As.

Now my question is how do you keep a user from "copying or saving" over
a file with another file. Is this possible? I sure hope it is because
this definitely would lock down a file. It has been my experience that
excel files are always exposed to being copied over if a user has rights
to that directory. Is that correct? I hope not.

Thank you,

Steven


It's a nice question, but it's not a nice solution as far as I can see.

On any file, when you go to the right-click-properties dialog you can
tick the "Read-Only" attribute. That'll stop anyone accidentally using a
Saveas to clobber your file, but it does have the side-effect that when
you open the file it'll be read-only, so no-one can make any changes
either.

You could set the read-only property dynamically every time you open/
close the file, although it's a lot of effort. You need to reference
Microsoft Scripting Runtime (scrrun.dll) from tools, references.
Something like this:

Private Sub Workbook_Open()
Dim fso As FileSystemObject
Dim thisfile As File

Set fso = CreateObject("scripting.filesystemobject")
Set thisfile = fso.GetFile(ThisWorkbook.FullName)
thisfile.Attributes = Normal ' remove read-only setting

ThisWorkbook.ChangeFileAccess (xlReadWrite) ' open for editing

End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save ' file has to save before it becomes readonly

Dim fso As FileSystemObject
Dim thisfile As File
Set fso = CreateObject("scripting.filesystemobject")
Set thisfile = fso.GetFile(ThisWorkbook.FullName)
thisfile.Attributes = Scripting.ReadOnly

Cancel = False
End Sub


Although I've lost the "would you like to save your changes" dialog, and
if someone really wanted to destroy your file, they still could. Far
easier is just to keep a backup.

Pip
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Ultimate Problem Gordon[_2_] Excel Programming 2 June 7th 06 10:26 PM
My ultimate goal is to create an ID that will always be unique KR Excel Programming 0 May 15th 06 02:13 PM
My ultimate goal is to create an ID that will always be unique RB Smissaert Excel Programming 0 May 12th 06 02:18 PM
The ultimate Reference Guide to VBA in Excel Martin Knudsen Excel Programming 7 February 9th 06 09:24 AM
Ultimate protection shnim1 Excel Discussion (Misc queries) 1 October 18th 05 02:11 AM


All times are GMT +1. The time now is 04:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"