Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-20-2022, 07:05 AM
grNadpa grNadpa is offline Cannot save Building Block templates with project Windows 10 Cannot save Building Block templates with project Office 2016
Advanced Beginner
Cannot save Building Block templates with project
 
Join Date: Mar 2022
Posts: 46
grNadpa is on a distinguished road
Default Cannot save Building Block templates with project

Code:
Application.Templates( _
        "C:\Users\" & Environ("username") & "\AppData\Roaming\Microsoft\Document Building Blocks\1033\16\Building Blocks.dotx" _
        ).BuildingBlockEntries("aNotaryForm").Insert Where:=Selection.range, _
        RichText:=True
blows up with the error
Quote:
Run-time error '5941': The requested member of the collection does not exist.
I figured out the reason is that neither
Code:
TemplateProject(Building Blocks) nor
TemplateProject(Built-in Building Blocks)
exist in my project window.
When I load them by inserting them from quick parts in the underlying document. They work fine. But when I save the application, and re-open, the template projects are missing.


Is there a way to keep them with the project? Or load the templates on instantiation?

Last edited by grNadpa; 03-20-2022 at 07:06 AM. Reason: typos
Reply With Quote
  #2  
Old 03-20-2022, 12:56 PM
Charles Kenyon Charles Kenyon is offline Cannot save Building Block templates with project Windows 10 Cannot save Building Block templates with project Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,474
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

See Where can Building Blocks be stored?.
They must be in templates, not documents.
Here is information on how to insert them using code:
Using VBA to Insent an AutoText Entry or other Building Block
Reply With Quote
  #3  
Old 03-20-2022, 02:59 PM
grNadpa grNadpa is offline Cannot save Building Block templates with project Windows 10 Cannot save Building Block templates with project Office 2016
Advanced Beginner
Cannot save Building Block templates with project
 
Join Date: Mar 2022
Posts: 46
grNadpa is on a distinguished road
Default

Your link states:
Quote:
If you are in an ordinary document (not a template) and want to save a building block to it, first save it as a template (.dotx unless you also want macros) and then save the building block.
So, that is clearly part of the problem. And I suspect (as an old mainframe programmer) I'm getting tripped up on terminology -- specifically "macro".

I think, in the link you supplied,
Quote:
Situation 1 - template holds both the building block and the macro
meets my needs if "macro" in this context is a generic term for "sub" and "function" that I can include within my form's code.

Without going into great detail here is what I have in development.
I have a userform that loads, instantiates, and unloads via command buttons the user's choice among a spreadsheet and two forms. One of the subordinate forms does the same for its two child forms. Three of those forms use building blocks stored in Quick Parts Gallery's Building Blocks.dotx in (custom) category "Waivers" named "aNotaryForm", "aPartialWaiver" and "aFinalWaiver".

Am I correct to expect that if I include the equivalent of your
Code:
Sub InsertMyBB()
into the form that uses "aNotaryForm" and the same code in the form that uses "aPartialWaiver" and so on that it should work if I save the whole "document" as "WaiverWorksheet.dotm"?
Reply With Quote
  #4  
Old 03-20-2022, 07:51 PM
Charles Kenyon Charles Kenyon is offline Cannot save Building Block templates with project Windows 10 Cannot save Building Block templates with project Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,474
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by grNadpa View Post
Your link states:

So, that is clearly part of the problem. And I suspect (as an old mainframe programmer) I'm getting tripped up on terminology -- specifically "macro".

I think, in the link you supplied, meets my needs if "macro" in this context is a generic term for "sub" and "function" that I can include within my form's code.

Without going into great detail here is what I have in development.
I have a userform that loads, instantiates, and unloads via command buttons the user's choice among a spreadsheet and two forms. One of the subordinate forms does the same for its two child forms. Three of those forms use building blocks stored in Quick Parts Gallery's Building Blocks.dotx in (custom) category "Waivers" named "aNotaryForm", "aPartialWaiver" and "aFinalWaiver".

Am I correct to expect that if I include the equivalent of your
Code:
Sub InsertMyBB()
into the form that uses "aNotaryForm" and the same code in the form that uses "aPartialWaiver" and so on that it should work if I save the whole "document" as "WaiverWorksheet.dotm"?
In Word, "macro" is pretty much synonymous with subroutine. It could be used to mean any vba code. It is not confined to recorded keystrokes.

As used in my page, I mean any code dealing with insertion of the building block. If the code is in the same template, then the location of the template containing the building block can always be identified as
Code:
ThisDocument.Fullname
in the code doing the insertion.

Yes. In Word jargon, a template is a particular kind of Word file. MS uses template to mean several things. See Templates in Microsoft Word.
Reply With Quote
  #5  
Old 03-21-2022, 07:18 AM
grNadpa grNadpa is offline Cannot save Building Block templates with project Windows 10 Cannot save Building Block templates with project Office 2016
Advanced Beginner
Cannot save Building Block templates with project
 
Join Date: Mar 2022
Posts: 46
grNadpa is on a distinguished road
Default

Thank you, Charles Kenyon. (with, according to your imbedded comment, additional kudos to Timothy Rylatt)
Apparently all that was missing from my code was:
Code:
Application.Templates.LoadBuildingBlocks ' Thank you Timothy Rylatt
Thanks for the links. The "Situation 1" did not work, but Situation 3 did. And after stepping through the Situation 3 code, found that it ultimately resolved to the code I originally posted the exception of the statement you attribute to Rylatt.

Given that I insert the same building block item multiple times in my application, I'm not sure whether to use Rylatt's statement on each insertion or just the first one. But experimentation will solve that issue.

Again thank you so much for your patience and suggestions.
Reply With Quote
Reply

Tags
building blocks, vba code, word 16.



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to build a custom building block template cos Word 1 12-13-2021 03:43 PM
VBA Word - Building Block (AutoText) - Array - Replace Text with Specific Building Blocks jc491 Word VBA 7 01-03-2016 10:34 PM
Cannot save Building Block templates with project How to share building block macros? rdross51 Word VBA 7 03-12-2015 08:59 AM
Cannot save Building Block templates with project Custom Building Block File Locations ptmuldoon Word 5 01-03-2015 08:45 AM
Building blocks show correctly in dropdown, but wrong building block populates in doc wordgirl123 Word 0 10-03-2013 08:30 AM

Other Forums: Access Forums

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