Solved

Save file over existing file with password

Posted on 2014-12-05
8
78 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 51

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Technology Partners: 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!

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 article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

724 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