Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 6th, 2012, 03:38 AM
Registered User
 
Join Date: Jul 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Wink Read-Only Files in VBA

Hi,

I have a file which I would like to make read-only and be able to save it (read-only again) from a button press in a sheet which has limited access to it - ie you need a password to gain access to that sheet .... the limited access with password bit is all done. I have code (below) to save the file when not read only, but how can I make a file read-only, so that I can save it through vba software so that it remains read-only. Is it possible to do it in a way that is similar to protecting a sheet (ActiveSheet.Unprotect "test" & ActiveSheet.Protect "test")??

My (non-Read only code) is below ......

Dim progname As String
progname = Sheets("Data").Range("C30").Value
'
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
progname, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Application.DisplayAlerts = True
'

I understand there is the SetAttr statement, but I want to do it from the name progfile, rather than list the whole program name in commas ie "C:\documents\test\......" as the name is quite long.

Any help would be greatly appreciated, Thanks.

Ross
 
Old April 6th, 2012, 04:05 AM
Registered User
 
Join Date: Jul 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Forgot to mention that I am using Excel 2010

Thanks,
Ross
 
Old April 9th, 2012, 10:19 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi Ross

Did you try using SetAttr in VBA

Regards
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old April 28th, 2012, 05:30 AM
Registered User
 
Join Date: Jul 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I did try it, but it didnt work :(





Similar Threads
Thread Thread Starter Forum Replies Last Post
read pdf files in C# prasannatele Visual Studio 2005 0 September 12th, 2007 05:46 AM
creating read-only files Fat_and_immoral Excel VBA 4 December 20th, 2006 09:24 AM
how to read files in evc++ iriskab Visual C++ 1 September 1st, 2006 04:19 AM
Writing Files that can't be read Ron_Bingham BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 April 23rd, 2005 02:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.