Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-14-2023, 05:07 AM
suuki suuki is offline Problem with quick parts Windows 11 Problem with quick parts Office 2016
Novice
Problem with quick parts
 
Join Date: May 2023
Posts: 1
suuki is on a distinguished road
Default Problem with quick parts

Hi there. I am trying to use this feature to replace a text with another.
I have already selected the text and went to quicks parts/autotext/save selection to autotext gallery


However when I run the macro, I got the error 5941, telling that the element doesn't exist. I checked the name used to save the selected text and it is correct, so I dont know what is the problem.


The macro is the following:


Sub Document_Open()


SubstitutePage
End Sub
Sub AutoOpen()
SubstitutePage
End Sub
Sub SubstitutePage()
ActiveDocument.Content.Select
Selection.Delete
ActiveDocument.AttachedTemplate.AutoTextEntries("a ne").Insert Where:=Selection.Range, RichText:=True
End Sub
Reply With Quote
  #2  
Old 05-14-2023, 09:16 AM
gmayor's Avatar
gmayor gmayor is offline Problem with quick parts Windows 10 Problem with quick parts Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
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

Change the code to
Code:
Sub SubstitutePage()
ActiveDocument.Content.Delete
ActiveDocument.AttachedTemplate.AutoTextEntries("a ne").Insert _
    Where:=ActiveDocument.Range, _
    RichText:=True
End Sub
However why not simply create a template with the required text already present and create the new documents with the required content from that?
__________________
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
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with quick parts Quick Tables disappear when emailed - quick parts / building blocks silawtz Word 5 11-03-2022 07:44 PM
Problem with quick parts Quick Parts-Need to be removed from TOC Isaac Word 3 05-11-2017 04:43 AM
Problem with quick parts Quick Parts Fields? brucemc777 Word 2 02-16-2016 12:57 PM
Problem with quick parts Quick Parts tmneal74 Word 1 11-13-2012 06:04 PM
Problem with quick parts Quick parts in doc file alokmay Word 1 06-14-2011 04:46 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:58 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