?
Solved

Save file over existing file with password

Posted on 2014-12-05
8
Medium Priority
?
80 Views
Last Modified: 2014-12-09
I use the below code to save a file with a date and a password

ActiveWorkbook.SaveAs Filename:="\\ukancbdata02\S-gdata\AllFiles\Recon\London\Events\Consolidated Report\Consolidated " & Format(DateAdd("d", -0, Date), "YYYY") & ".xls", _
    FileFormat:=xlNormal, Password:="", WriteResPassword:="pact", _
        ReadOnlyRecommended:=True, CreateBackup:=False


What I need to do do is overwrite the file each day but because it is password protected the code returns an error.

Could an Expert provide me with the code that will enable me to save the file each day over the existing file with the password.
0
Comment
Question by:Jagwarman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 40482731
HI,

which PW is missing

ActiveWorkbook.SaveAs Filename:="\\ukancbdata02\S-gdata\AllFiles\Recon\London\Events\Consolidated Report\Consolidated " & Format(DateAdd("d", -0, Date), "YYYY") & ".xls", _
    FileFormat:=xlNormal, Password:="", WriteResPassword:="pact", _
        ReadOnlyRecommended:=True, CreateBackup:=False

Regards
0
 

Author Comment

by:Jagwarman
ID: 40482901
Hi Rgonzo, soory not sure I understand the question.

when the original file was saved, it was saved with a password. If I open the file manually I am asked for a password and then I get asked "Open as Read Only?"

So now I want to save over this file.

 Does this answer your question?
0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 40482921
I just created a simple file and saved with a password. I then closed the file and tried saving another file with the same name and it gave me the usual "File exists, Replace" warning to which I clicked Yes and the file overwrote with no problem.

Have you closed the original file before trying to Overwrite?

If you are doing changes in the open file which you want to save, just use "ActiveWorkbook.Save" command. The password will be retained for future use.

Thanks
Rob H
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Jagwarman
ID: 40483176
Hi Rob,

If I open the original file and the save it down its fine.

If I create a new file and call it the same name it does not work.

So maybe it's not possible.
0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 40483218
That's exactly what I did. Created file and saved with password. Closed file, created new file and saved with same name, overwrote fine after confirming message.
0
 

Author Comment

by:Jagwarman
ID: 40486489
Hi Rob,

when I save outside of a Macro it does exactly what you say. When I try to get the Macro to save it I get error saying the file is Write protected.
0
 
LVL 33

Accepted Solution

by:
Rob Henson earned 2000 total points
ID: 40486498
Bizarre, just tried it myself and got the same but got it to work using the following:

ActiveWorkbook.SaveAs Filename:= _
        "C:\Users\lu677d\Documents\Personal\EE\With Password.xlsx", FileFormat:= _
        xlOpenXMLWorkbook, Password:="", WriteResPassword:="pact", _
        ReadOnlyRecommended:=True, CreateBackup:=False

Open in new window


Note the format change. You just need to change the filename bit back to how you want it.

Thanks
Rob H
0
 

Author Comment

by:Jagwarman
ID: 40488681
Hi Rob thanks for working on this and sorting it.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question