Results 1 to 6 of 6

Thread: Code to insert a building block via a check box

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Code to insert a building block via a check box

    Regarding [SOLVED] Code to insert a building block via a check box (vbaexpress.com)

    I'm trying the following
    Schermafbeelding 2022-07-12 090831.png

    If Mobile is Yes then Building block With mobile phone is inserted at Bookmark MainText
    If Mobile is No then Building block Without mobile phone is inserted at Bookmark MainText

    Private Sub CancelButton_Click()    
    UserInfo.Hide
    End Sub
    
    Private Sub OkButton_Click()
    Set ovars = ActiveDocument.Variables
    Dim oRng As Word.Range
    If OptionButton1.Value Then
            Set oRng = ThisDocument.AttachedTemplate.BuildingBlockTypes(wdTypeAutoText). _
            Categories("general").BuildingBlocks("With mobiel phone").Insert(ActiveDocument.Bookmarks("MainText").Range, True)
            ActiveDocument.Bookmarks.Add "MainText", oRng
    End If
    If OptionButton2.Value Then
            Set oRng = ThisDocument.AttachedTemplate.BuildingBlockTypes(wdTypeAutoText). _
            Categories("general").BuildingBlocks("Without mobiel phone").Insert(ActiveDocument.Bookmarks("MainText").Range, True)
            ActiveDocument.Bookmarks.Add "MainText", oRng
    End If
    Hide
    Me.Hide
    ActiveDocument.Fields.Update
    Unload Me
    End Sub
    I'm getting Error 591.
    Any ideas?

    As an extra I would like to have the oportunity to insert an image (if possible) and have it inserted at Bookmark space Image.
    Last edited by Aussiebear; 07-12-2022 at 12:48 AM. Reason: Reduced whitespace

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •