Share via

Word VBA Insert Building Block

Anonymous
2018-12-27T16:23:31+00:00

Hi, I have a macro that deletes what's below the first table on the first page of a document and inserts new table from a source document.  I would rather use a building block.  I can't seem to figure out how to modify this code to do that. This macro seems to work best at getting rid of the empty paragraphs that vary from document to document. 

Dim DocSrc As Document, RngTgt As Range

 Set RngTgt = ActiveDocument.Sections.First.Range

 With RngTgt

   .End = .End - 1

   .Start = .Tables(1).Range.End + 1

 End With

 Set DocSrc = Documents.Open(FileName:="C:\Procedure Macros\Sign-in Cover Page.doc", _

   ReadOnly:=True, AddToRecentFiles:=False, Visible:=False)

 RngTgt.FormattedText = DocSrc.Range.FormattedText

 DocSrc.Close False

Any ideas?

thanks, Cindy

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2018-12-29T11:38:12+00:00

Hi Cindy,

VBA code to access building blocks looks like the following:

Sub InsertBuildingBlock()

    ActiveDocument.attachedTemplate.BuildingBlockEntries("AuthorTec Caption Title").Insert _

        Where:=Selection.Range, RichText:=True

End Sub

I prefer to use AutoText because it is compatible across Windows and Mac environments.

iDoc.AttachedTemplate.AutoTextEntries(strBlockName).Insert(Where:=wApp.Selection.Range, RichText:=True)

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

Anonymous
2018-12-27T16:50:47+00:00

Hi,

Building Blocks have a number of components that make recorded macros not work well with them.

See Using VBA to Insent an AutoText Entry or other Building Block  for instructions.

I hope this information helps. Please let me know if you have any more questions or require further help.

Regards

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2018-12-31T16:42:49+00:00

    I have changed to AutoText and modified the code a bit to account for the variation in empty paragraphs and it is now working great!

    thanks to you and Charles for your help!

    Cindy

    Was this answer helpful?

    0 comments No comments