Building Blocks Output Word Doc - Compile errror

J

Jules

Hi all, Cindy Meister suggested this code to create a list of BBs in a Word document but I keep getting "Compile error variable not defined?" - all the variables seem to be defined? The references seem to be set?

Any ideas please?


Set objBBC = objCat.BuildingBlocks
For i = 1 To objBBC.Count 'Compile error variable not defined?
Set objBB = objBBC(i)



Sub SearchableBuildingBlocksMacro()

'The macro creates a Word document. Each building block in the
'template is inserted on a new page and labeled.


Dim objTemplate As Template
Dim objBBT As BuildingBlockType
Dim objCat As Category
Dim intCount As Integer
Dim intCountCat As Integer


Dim objBB As BuildingBlock
Dim objBBC As BuildingBlocks


Documents.Add


'next line saves in the current default folder on the current drive
ActiveDocument.SaveAs FileName:="SearchableBuildingBlocks.docx"


'change next line to match location on your hard drive
ActiveDocument.AttachedTemplate = "C:\Documents and Settings\docsliveonline.com\Application Data\Microsoft\Document Building Blocks\1033\Building Blocks.dotx"
'repeat macro when done, substituting other building block templates including the Normal template


Set objTemplate = ActiveDocument.AttachedTemplate


For intCount = 1 To objTemplate.BuildingBlockTypes.Count
Set objBBT = objTemplate.BuildingBlockTypes(intCount)
If objBBT.Categories.Count > 0 Then
For intCountCat = 1 To objBBT.Categories.Count
Set objCat = objBBT.Categories(intCountCat)


Set objBBC = objCat.BuildingBlocks
For i = 1 To objBBC.Count 'Compile error variable not defined?
Set objBB = objBBC(i)


Selection.TypeText Text:="Building Block Name:" & vbTab & objBB.Name
Selection.TypeParagraph


Selection.TypeText Text:="Gallery:" & vbTab & objBBT.Name
Selection.TypeParagraph


Selection.TypeText Text:="Category:" & vbTab & objCat.Name
Selection.TypeParagraph


Selection.TypeText Text:="Description (in any):" & vbTab & objBB.Description
Selection.TypeParagraph


objBB.Insert Selection.Range
Selection.InsertBreak Type:=wdSectionBreakNextPage
ActiveDocument.Save
Next i


Next intCountCat
End If
Next intCount


ActiveDocument.AttachedTemplate = ""
ActiveDocument.Save

End Sub
 
J

Jules

Oops, Cindy was not code provider.

Hi all, Cindy Meister suggested this code to create a list of BBs in a Word document but I keep getting "Compile error variable not defined?" - all the variables seem to be defined? The references seem to be set?

Any ideas please?


Set objBBC = objCat.BuildingBlocks
For i = 1 To objBBC.Count 'Compile error variable not defined?
Set objBB = objBBC(i)



Sub SearchableBuildingBlocksMacro()

'The macro creates a Word document. Each building block in the
'template is inserted on a new page and labeled.


Dim objTemplate As Template
Dim objBBT As BuildingBlockType
Dim objCat As Category
Dim intCount As Integer
Dim intCountCat As Integer


Dim objBB As BuildingBlock
Dim objBBC As BuildingBlocks


Documents.Add


'next line saves in the current default folder on the current drive
ActiveDocument.SaveAs FileName:="SearchableBuildingBlocks.docx"


'change next line to match location on your hard drive
ActiveDocument.AttachedTemplate = "C:\Documents and Settings\docsliveonline.com\Application Data\Microsoft\Document Building Blocks\1033\Building Blocks.dotx"
'repeat macro when done, substituting other building block templates including the Normal template


Set objTemplate = ActiveDocument.AttachedTemplate


For intCount = 1 To objTemplate.BuildingBlockTypes.Count
Set objBBT = objTemplate.BuildingBlockTypes(intCount)
If objBBT.Categories.Count > 0 Then
For intCountCat = 1 To objBBT.Categories.Count
Set objCat = objBBT.Categories(intCountCat)


Set objBBC = objCat.BuildingBlocks
For i = 1 To objBBC.Count 'Compile error variable not defined?
Set objBB = objBBC(i)


Selection.TypeText Text:="Building Block Name:" & vbTab & objBB.Name
Selection.TypeParagraph


Selection.TypeText Text:="Gallery:" & vbTab & objBBT.Name
Selection.TypeParagraph


Selection.TypeText Text:="Category:" & vbTab & objCat.Name
Selection.TypeParagraph


Selection.TypeText Text:="Description (in any):" & vbTab & objBB.Description
Selection.TypeParagraph


objBB.Insert Selection.Range
Selection.InsertBreak Type:=wdSectionBreakNextPage
ActiveDocument.Save
Next i


Next intCountCat
End If
Next intCount


ActiveDocument.AttachedTemplate = ""
ActiveDocument.Save

End Sub
 
J

Jay Freedman

After the line that starts "Dim iCountCat" add another line:

Dim i As Integer

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
J

Jean-Guy Marcil

Jules said:
Hi all, Cindy Meister suggested this code to create a list of BBs in a Word document but I keep getting "Compile error variable not defined?" - all the variables seem to be defined? The references seem to be set?

Any ideas please?


Set objBBC = objCat.BuildingBlocks
For i = 1 To objBBC.Count 'Compile error variable not defined?
Set objBB = objBBC(i)

I do not see any Dim statement for i, such as:

Dim i As Long

By the way, you should use Long instead of Integer becasue the compiler has
to convert all your Integers into Longs (Longs are now the smallest unit of
allocatable memory).
 
J

Jules

Thanks (yes) but it seems I'm forever adding this statement to a lot of my
macros lately? Dim i As Integer?

Thanks everyone
 
J

Jules

Thanks for that Jean-Guy that makes it clearer.


Jean-Guy Marcil said:
I do not see any Dim statement for i, such as:

Dim i As Long

By the way, you should use Long instead of Integer becasue the compiler
has
to convert all your Integers into Longs (Longs are now the smallest unit
of
allocatable memory).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top