Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 985
  • Last Modified:

Locked Excel file is unlocked when re-opened

I use the following code to lock a new file and then close it.  When I open it is unlocked and headings are visible.  The code works fine as I step through it...but the file is not locked when I open it. Can someone tell me what I am doing wrong? Thanks
Workbooks.Add
ActiveWorkbook.SaveAs Filename:= ...etc
With ActiveWindow
.DisplayHeadings = False
.DisplayVertivleScrollBar = False
.DisplayWorkTabs = False
End With
ActiveSheet.Protec Password = 1234
ActiveWorkbook.Close SaveChanges = True

Open in new window

0
davidam
Asked:
davidam
  • 7
  • 3
  • 2
4 Solutions
 
rspahitzCommented:
maybe you misspelled the word protect on line 8?

ActiveSheet.Protec Password = 1234
0
 
florjanCommented:
I belive you had a typo. So it's Protect not Protec.
ActiveSheet.Protect Password = 1234

Open in new window

0
 
davidamAuthor Commented:
No, it is correct in the code.  I typed it on a different computer for this.  When I step throught the code it locks the file and then closes it...it is unlocked when I open it.
0
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!

 
davidamAuthor Commented:
Further to the above...and probably a very good clue...I stepped through the code again...right up until the last line (close save)..then I suspended the macro and manually closed the file.  Upon opening it it was fully locked.
0
 
florjanCommented:
ActiveWorkbooks.Close SaveChanges = True

Open in new window

Workbooks not workbook?
0
 
davidamAuthor Commented:
Actually I think I need ActiveWorkbooks.Close SaveChanges:= True
...what I really need is for this project to end!!!  Thanks to all.
0
 
rspahitzCommented:
Seems that florjan should get a little credit for finding the answer, but maybe not 500 points...I guess it depends on whether author would have found the answer without EE help.
0
 
davidamAuthor Commented:
I have no objection to rewarding points.  I accepted my solution because I did not want anyone to waste any more time on this and because I had indeed discovered the true issue.  rspahitz was certainly zeroing in on the line that was causing the problem.  I am new to this and I would like someone else to decide how many points should be awarded.
0
 
rspahitzCommented:
I would suggest 100 pts awarded to florjan, with grade A if it worked as delivered (or with minor change)
0
 
davidamAuthor Commented:
That sounds good to me...but I do not know how to do this.
0
 
davidamAuthor Commented:
This is a syntax problem, the solution is
ActiveWorkbooks.Close SaveChanges:= True
0
 
davidamAuthor Commented:
Both spahitz and florjan found an error in my code; ultimately it was a different error that was the problem
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now