Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-25-2023, 08:25 AM
darkmaster006 darkmaster006 is offline Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros) Windows 10 Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros) Office 2021
Novice
Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros)
 
Join Date: Aug 2023
Posts: 10
darkmaster006 is on a distinguished road
Default 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).
Reply With Quote
  #2  
Old 08-25-2023, 10:37 PM
gmayor's Avatar
gmayor gmayor is offline Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros) Windows 10 Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros) Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 08-26-2023, 11:22 AM
Italophile Italophile is offline Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros) Windows 11 Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros) Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

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.
Reply With Quote
  #4  
Old 08-27-2023, 11:14 PM
darkmaster006 darkmaster006 is offline Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros) Windows 10 Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros) Office 2021
Novice
Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros)
 
Join Date: Aug 2023
Posts: 10
darkmaster006 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
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.
I see. Thank you!

Quote:
Originally Posted by Italophile View Post
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.
Oh, I see, then, I will check that! Thank you .
Reply With Quote
  #5  
Old 08-28-2023, 04:59 PM
Guessed's Avatar
Guessed Guessed is offline Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros) Windows 10 Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros) Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #6  
Old 08-29-2023, 01:04 PM
Italophile Italophile is offline Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros) Windows 11 Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros) Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Quote:
Originally Posted by Guessed View Post
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.
The message is related to the origin of the files, not that they contain macros. Documents received by email or downloaded from the internet are automatically blocked for editing regardless of whether they contain code. When opened for the first time Word displays the message included in the initial post.
Reply With Quote
Reply

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
Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros) 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
Enable Editing for "Protected View" documents automatically? (in order to run AutoOpen macros) Making a Macro "autoopen" Joshocom Word 1 03-16-2010 05:03 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:28 PM.


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