Solved

Save file over existing file with password

Posted on 2014-12-05
8
76 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
  • 4
  • 3
8 Comments
 
LVL 50

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
Industry Leaders: 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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

685 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