Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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
 

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:34 AM.


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