Insert Building Block into the third row of the first column of thecurrently selected table.

A

andreas

Dear Experts:

I got VBA code to insert a user-defined building block into the
current document

ActiveDocument.AttachedTemplate.BuildingBlockEntries( _
'"MS_CoverSheet_Version").Insert Where:=Selection.Range,
RichText:=True


I would like to insert this building block into the third row of the
first column of the currently selected table. The paragraph setting of
the inserted building block should have the property "Space Before 150
pt".

Could somebody please help me to achieve this.

Thank you very much in advance

Regards, Andreas
 
J

Jay Freedman

Hi Andreas,

Use a Range object this way:

Dim myRange As Range
If Selection.Information(wdWithInTable) Then
Set myRange = Selection.Tables(1).Cell( _
Row:=3, Column:=1).Range
myRange.MoveEnd wdCharacter, -1 ' exclude cell marker
ActiveDocument.AttachedTemplate.BuildingBlockEntries( _
"MS_CoverSheet_Version").Insert _
Where:=myRange, RichText:=True
End If

If the Selection is anywhere within a table, then Selection.Tables(1)
identifies that table. Then the .Cell method identifies the cell in
row 3 of column 1. You'll get an error if you forget to exclude the
cell marker from the end of the range before inserting the building
block.
 
A

andreas

Hi Andreas,

Use a Range object this way:

    Dim myRange As Range
    If Selection.Information(wdWithInTable) Then
        Set myRange = Selection.Tables(1).Cell( _
            Row:=3, Column:=1).Range
        myRange.MoveEnd wdCharacter, -1  ' exclude cell marker
        ActiveDocument.AttachedTemplate.BuildingBlockEntries( _
            "MS_CoverSheet_Version").Insert _
            Where:=myRange, RichText:=True
    End If

If the Selection is anywhere within a table, then Selection.Tables(1)
identifies that table. Then the .Cell method identifies the cell in
row 3 of column 1. You'll get an error if you forget to exclude the
cell marker from the end of the range before inserting the building
block.









- Zitierten Text anzeigen -

Hi Jay,

terrific support. Thank you very much for your superb help.

Regards, Andreas
 

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