PC Review


Reply
Thread Tools Rate Thread

Creating a Macro that saves over a protected spreadsheet.

 
 
Dolores
Guest
Posts: n/a
 
      14th Oct 2008
Is there a way to create a macro that can save over a protected file.


I used the macro record tool that comes with excel, to record the save as
function, however the document I am trying to save over is a protected file,
so I keep getting an error. Is there some code that can be added to my macro
listed below so that I do not have to manually unprotect my file before I run
the macro?

Sub saveas()
'
' saveas Macro
' Macro recorded 9/30/2008 by dgomez
'
ChDir "F:\Illinois-Indy Sales"
ActiveWorkbook.saveas Filename:="F:\Illinois-Indy Sales\Bid
Register.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End Sub

when I run the macro I get the following error "Cannot access read-only
document "Bid Register.xls"

 
Reply With Quote
 
 
 
 
Barb Reinhardt
Guest
Posts: n/a
 
      14th Oct 2008
I'm thinking that the file is set up with an attribute of READ ONLY. You
can find this by right clicking on the file name and selecting PROPERTIES.

I don't know of a way to change this programmatically, but I've never looked
into it either. Maybe someone else can assist.
--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"Dolores" wrote:

> Is there a way to create a macro that can save over a protected file.
>
>
> I used the macro record tool that comes with excel, to record the save as
> function, however the document I am trying to save over is a protected file,
> so I keep getting an error. Is there some code that can be added to my macro
> listed below so that I do not have to manually unprotect my file before I run
> the macro?
>
> Sub saveas()
> '
> ' saveas Macro
> ' Macro recorded 9/30/2008 by dgomez
> '
> ChDir "F:\Illinois-Indy Sales"
> ActiveWorkbook.saveas Filename:="F:\Illinois-Indy Sales\Bid
> Register.xls", _
> FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
> ReadOnlyRecommended:=False, CreateBackup:=False
> End Sub
>
> when I run the macro I get the following error "Cannot access read-only
> document "Bid Register.xls"
>

 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      14th Oct 2008
>I don't know of a way to change this programmatically,

Code like the following will set or clear the read-only flag for a
file.

Dim FName As String
FName = "C:\DirTree\Readme.txt"
' set read only flag
SetAttr FName, vbNormal + vbReadOnly
' clear read only flag
SetAttr FName, vbNormal

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Tue, 14 Oct 2008 08:21:02 -0700, Barb Reinhardt
<(E-Mail Removed)> wrote:

>I'm thinking that the file is set up with an attribute of READ ONLY. You
>can find this by right clicking on the file name and selecting PROPERTIES.
>
>I don't know of a way to change this programmatically, but I've never looked
>into it either. Maybe someone else can assist.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i copy protected spreadsheet in a macro R Davis Microsoft Excel Misc 1 23rd Jul 2009 03:44 PM
Macro doesn't insert image when spreadsheet is protected =?Utf-8?B?QVRhbmc=?= Microsoft Excel Worksheet Functions 4 12th Sep 2006 03:14 AM
Macro doesn't insert image when spreadsheet is protected =?Utf-8?B?QVRhbmc=?= Microsoft Excel Worksheet Functions 0 11th Sep 2006 09:00 AM
I need a macro that saves a spreadsheet on two drive at once, =?Utf-8?B?Q2hhdW5jeV9H?= Microsoft Excel Worksheet Functions 3 24th Jul 2006 09:12 PM
macro creating a spreadsheet Rick Microsoft Excel Programming 2 28th Oct 2004 11:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:01 PM.