Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-28-2022, 01:03 AM
data808 data808 is offline VBA to lock everything after Save As Windows 10 VBA to lock everything after Save As Office 2019
Novice
VBA to lock everything after Save As
 
Join Date: Oct 2022
Posts: 16
data808 is on a distinguished road
Default VBA to lock everything after Save As

I have a macro assigned to a button that does a Save As and names the file in a specific location. The document is already password protected from edits with exceptions to only the text boxes that the user must fill out. Once the user is done filling out the text boxes they click the macro button and the file is saved as a .docx file. When I go to open the newly created .docx file, I would like it to be completely locked from edits. Is there a way to do this? I've tried recording macros just to see what it would take to lock all the text boxes once the user clicks the button but the only code I got was this:



Selection.Editors(wdEditorEveryone).Delete
Selection.Editors(wdEditorEveryone).Delete
Selection.Editors(wdEditorEveryone).Delete
Selection.Editors(wdEditorEveryone).Delete
Selection.Editors(wdEditorEveryone).Delete

Which is quite puzzling since its not referring to any particular text box so if I were to type this code for the button, how would it know which box to not allow everyone to edit anymore? I also tried this code at the end after the Save As already triggered but it didn't see to work:

ActiveDocument.Unprotect "hello"
ActiveDocument.Protect Password:="hello", NoReset:=False, Type:= _
wdAllowOnlyReading, UseIRM:=False, EnforceStyleLock:=False
ActiveDocument.Save

I had to unprotect it first as it was already protected with the exception of the text boxes that the user could edit. Then I wanted to protect the whole document from edits and this is the code it produced when I recorded a macro to lock the document with No Changes (Read Only).

Excel seems to be much more intuitive when it comes to writing VBA and using the record macro feature to help write VBA code. I feel Word leaves you more in the dark. Any help is appreciated. Thank you!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to lock everything after Save As Lock in Watermark barrycc Word 2 05-24-2017 07:50 AM
Any way to lock tab stops ctenanthe Word 1 01-31-2013 11:20 PM
VBA to lock everything after Save As When I try to save an existing word doc, save as pops up and will not save... samanthab Word 3 01-19-2013 06:27 AM
Num Lock ERROR judicial85 Excel 6 05-04-2012 10:43 AM
Lock a Slide Pemberton PowerPoint 0 07-18-2010 04:43 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:03 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft