|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros)
Hello there! So, I have a quite long AutoOpen macro running, which does many things: it changes the font to black, it erases fill backgrounds, it makes it possible to set the document background automatically to another colour in already created documents, etc. This is the code:
Code:
Sub AutoOpen() ' ' AutoOpen Macro ' ' This macro opens itself (AutoOpen) automatically with every Word document that's opened normally ' Choose background colour (light green 2) ActiveDocument.Background.Fill.ForeColor.ObjectThemeColor = wdThemeColorAccent6 ActiveDocument.Background.Fill.ForeColor.TintAndShade = 0.6 ActiveDocument.Background.Fill.Visible = msoTrue ActiveDocument.Background.Fill.Solid ' Turn option 'Show background colors and images in Display view' on ActiveWindow.View.DisplayBackgrounds = True ' Change all text font to black colour ActiveDocument.Content.Font.Color = wdColorBlack ' Change all text and change "fill shading" background to no colour https://www.msofficeforums.com/word-vba/51216-change-fill-text-colour-colour.html With ActiveDocument.Content.ParagraphFormat .Shading.Texture = wdTextureNone .Shading.ForegroundPatternColor = wdColorAutomatic .Shading.BackgroundPatternColor = wdColorAutomatic End With ' Change all paragraphs with fill to no fill (from https://www.msofficeforums.com/word-vba/51216-change-fill-text-colour-colour.html) Application.ScreenUpdating = False 'If the selection includes tables, error 4605 will be returned. 'Thus an error handler is needed: On Error Resume Next For Each oPara In ActiveDocument.Range.Paragraphs oPara.Range.Select Selection.End = Selection.End - 1 Selection.Shading.BackgroundPatternColor = wdColorAutomatic Next oPara Application.ScreenUpdating = True Selection.HomeKey Unit:=wdStory End Sub Now, when I open a file with "Protected View", an error appears before I can even "Enable Editing". This is the error: Run-time error '4288': The command is not available because no document is open. I believe this error appears because the document has not been enable for editing (and cannot be). Therefore, to make this automatic, I'd like to add a code that enables editing in any document opened with the AutoOpen macro; the code would go first, so that the rest of the code would be able to run. Protected View. Error in the code (first line, cannot run). |
#2
|
||||
|
||||
What you ask is not possible. If you could do this it would open the door to no end of malicious actions. You would have to remove the protection before opening the document if you want your macro to run.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Although you can enable editing when you see the banner in Word it is the OS that blocks the file based on how it was received. So you’ll need to open file explorer and display the file properties for each file. You’ll find a button marked Unblock.
AFAIK there is no way of removing the block for multiple files at once. |
#4
|
|||
|
|||
Quote:
Quote:
|
#5
|
||||
|
||||
The way a corporate user would enable macros is to place the vba in a template which can be pre-loaded to the user machines so that the code is already trusted. Then your documents don't need to contain any code but they have that template set as the attached template.
Because the code is then coming from a trusted location, it can run without requiring 'enabling' or unblocking.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#6
|
|||
|
|||
Quote:
|
Tags |
enable editing, protected view |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Inserting Caption: "Protects Documents" prevents Editing | Phil Stunell | Word | 13 | 03-19-2021 03:30 PM |
Documents spontaneously become "read only" while I'm editing them | Junebugsin | Word | 1 | 04-27-2018 06:39 PM |
Force a user to enable macros in Powerpoint? Hide sheets until the "enable" button is clicked | copleyr | PowerPoint | 1 | 10-07-2016 01:15 AM |
How do I delete the names under "Exceptions" when I use the "Restrict Editing" feature in Word? | MengS | Word | 0 | 02-25-2015 02:57 PM |
Making a Macro "autoopen" | Joshocom | Word | 1 | 03-16-2010 05:03 PM |