Share via

How to solve the problem of inserting a table by macro without doing further manual step in Word?

Anonymous
2022-04-08T08:43:37+00:00

Hello,

In Word, I recorded a new macro to insert a table that exists in Quick Tables, which is Calendar 1, but when I run the macro by using the shortcut of the macro that I set before, it appears an error message and the macro doesn't work. As I know to solve this problem I have to click on the "Quick Tables" button, but this is a temporary solution because when I close the Word and open it again, the problem comes again and the macro doesn't work. See the following pictures for clarifying.

This is the table that I want to insert by the macro:

These are the commands of the macro the I recorded to insert the table:

Sub Macro41()

'

' Macro41 Macro

' Macro of Ctrl+. to insert from Quick Tables

'

Application.Templates( \_ 

    "C:\Users\Ahmed\AppData\Roaming\Microsoft\Document Building Blocks\1033\16\Built-In Building Blocks.dotx" \_ 

    ).BuildingBlockEntries("Calendar 1").Insert Where:=Selection.Range, \_ 

    RichText:=True 

End Sub

This is the button that I have to click on it to solve the problem temporary, and this option is existing mainly in the "Insert" Tap from "Table" button:

This is the error message that appears when I run the macro, yes it's disappear when I click on the pervious button, but when I close the word and open it again, the problem comes again:

Do you know how to modify the macro or any way to make the macro inserts the table without finding this error message?

Microsoft 365 and Office | Word | For education | 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
  1. Stefan Blom 338.6K Reputation points MVP Volunteer Moderator
    2022-04-08T12:46:03+00:00

    As shown in my previous reply, the difference is the very first line of code:

    Application.Templates.LoadBuildingBlocks
    

    Open the Visual Basic Editor and add the line of code to your macro.

    2 people found this answer helpful.
    0 comments No comments
Answer accepted by question author
  1. Stefan Blom 338.6K Reputation points MVP Volunteer Moderator
    2022-04-08T11:13:18+00:00

    You have to add a statement that loads the building block templates into memory:

    Application.Templates.LoadBuildingBlocks    'Added code line
    
    Application.Templates( \_ 
    
        "C:\Users\Ahmed\AppData\Roaming\Microsoft\Document Building Blocks\1033\16\Built-In Building Blocks.dotx" \_ 
    
        ).BuildingBlockEntries("Calendar 1").Insert Where:=Selection.Range, \_ 
    
        RichText:=True
    
    2 people found this answer helpful.
    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2022-04-08T13:11:34+00:00

    Thank you so so much mister Stefan for replying and clarifying this.

    0 comments No comments
  2. Anonymous
    2022-04-08T12:26:14+00:00

    Hello mister Stefan, I don't under stand exactly what I have to do or to add to modify the code, and to know the template that I use called Document Of Header

    0 comments No comments
  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more