BuildingBlockEntries.Add question

Comfrog
NewLounger
Posts: 6
Joined: 11 Jul 2023, 19:04

BuildingBlockEntries.Add question

Post by Comfrog »

I wanted to write some code that transfers autotextentries, which would work if you were just copying for the sake of copying and not copying them into the correct collections (read categories, types). I was then informed that copying buildingblocks from one document to another would be the correct way to do it to keep all of the specifics of the directory of the autotextentries, however I ran into a small problem.

When adding a new buildingblock entry into the template.BuildingBlockEntries via the .Add method, I get "Object doesn't support this property or method". Now, I believe that I have done it correctly, but I also don't know if what I am doing wrong is with the Add method, or if something I am inserting is the wrong type. I was getting type mismatches, but I believe that they're resolved. I've scoured every link on the first 3 pages of google on every single possible way to search this issue, yet not a single person has had this issue. Any help that points even in the general direction of the solution would be greatly appreciated.

Code: Select all

            Selection.Range.Text = ListBoxValue.List(i)
            
            If ListBoxInsertOptions.List(i) = "0" Then
            Debug.Print DocBlockTypes(1).Name
                Set entry = temp.BuildingBlockEntries.Add(Name:=ListBoxName.List(i), _
                    Type:=DocBlockTypes(ListBoxType.List(i)), Category:=ListBoxCategory.List(i), Range:=Selection.Range, _
                    Description:=ListBoxDescription.List(i), insertoptions:=wdInsertContent)
            ElseIf ListBoxInsertOptions.List(i) = "1" Then
                Set entry = temp.BuildingBlockEntries.Add(Name:=ListBoxName.List(i), _
                    Type:=DocBlockTypes(ListBoxType.List(i)), Category:=ListBoxCategory.List(i), Range:=Selection.Range, _
                    Description:=ListBoxDescription.List(i), insertoptions:=wdInsertParagraph)
            ElseIf ListBoxInsertOptions.List(i) = "2" Then
                Set entry = temp.BuildingBlockEntries.Add(Name:=ListBoxName.List(i), _
                    Type:=DocBlockTypes(ListBoxType.List(i)), Category:=ListBoxCategory.List(i), Range:=Selection.Range, _
                    Description:=ListBoxDescription.List(i), insertoptions:=wdInsertPage)
            End If
DocBlockTypes is a collection of BuildingBlockTypes that is in the template, which I believe is a singular constant within WdBuildingBlockTypes.

I've hacked a way around inserting the correct insertoptions based on the value of it within the listbox, so please ignore the very clearly poor choice of code for the elseif statements. They were quick placeholders until I got the problem figured out and then I would fix them, I swear!

User avatar
Charles Kenyon
5StarLounger
Posts: 635
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: BuildingBlockEntries.Add question

Post by Charles Kenyon »

Take a look at Greg Maxey's writing on Building Blocks. My vba has no idea what DocBlockTypes is.

I believe that Graham Mayor has an AutoText Backup and Restore utility that might help you.
http://www.gmayor.com/autotext_backup_and_restore.htm

snb
4StarLounger
Posts: 596
Joined: 14 Nov 2012, 16:06

Re: BuildingBlockEntries.Add question

Post by snb »

Without your file it's only guessing.
What e.g. is 'ListBoxValue", 'temp', 'ListBoxInsertOptions' ???

Comfrog
NewLounger
Posts: 6
Joined: 11 Jul 2023, 19:04

Re: BuildingBlockEntries.Add question

Post by Comfrog »

Charles Kenyon wrote:
20 Jul 2023, 02:39
My vba has no idea what DocBlockTypes is.
DocBlockTypes was just a collection object of buildingblocktypes;

Code: Select all

Dim DocBlockTypes As BuildingBlockTypes
The links you provided will help IMMENSELY, deeply appreciate the reply.
snb wrote:
20 Jul 2023, 09:31
Without your file it's only guessing.
What e.g. is 'ListBoxValue", 'temp', 'ListBoxInsertOptions' ???
Sorry, I should have been more clear about all my variables; All the listboxes contain simply just the information from the building block as Strings, and then I create the new building block out of it. All the listboxes have the same amount of entries in them (indices wise), which would correlate to each individual building block in the template I am transferring from. (all listboxes' item in index 1 are building block 1)
Temp is just the template that I am transferring in a building block into.
ListBoxValue is the "range" that I am transferring into the new building block, which is just the "value" of the building block, or the text/control/whatever that the building block contains.

User avatar
Charles Kenyon
5StarLounger
Posts: 635
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: BuildingBlockEntries.Add question

Post by Charles Kenyon »

Keep in mind that Building Blocks can contain much more than text.
They can be Cover Pages with Document Property Content Controls, Quick Tables, Tables of Contents, and multi-page formatted entries. None of that fits into text variables.
Whenever possible I insert building blocks by examples.

Comfrog
NewLounger
Posts: 6
Joined: 11 Jul 2023, 19:04

Re: BuildingBlockEntries.Add question

Post by Comfrog »

Charles Kenyon wrote:
20 Jul 2023, 22:56
Keep in mind that Building Blocks can contain much more than text.
Whenever possible I insert building blocks by examples.
Hmm, I forgot about that honestly, I will definitely use an example instead! :grin: