Announcement

Collapse
No announcement yet.

Word Macro not finding bookmarks IF they are inside textboxes

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Word Macro not finding bookmarks IF they are inside textboxes



    Hi there! Thank you for taking the time to read my question.

    I am working on a report generator in VBA that runs from a macro-enabled word document, and queries a macro-enabled excel workbook.

    I have managed to get values within specific cells to update bookmarks within the word document.

    However, I get errors that certain bookmarks cannot be found, but only the ones that are within text boxes.

    Here is my code:
    Code:
    Public Sub RepGenWord()
    
        Dim oDoc As ThisDocument
    
        Dim xlApp As Excel.Application
        Dim xlSh As Excel.Workbook
        Dim FileToOpen As String
        
        Dim XAddress As String, XClient As String, XPhone As String, XEmail As String
        
        Set xlApp = CreateObject("Excel.Application")
        'xlApp.Visible = True
        
        FileToOpen = Excel.Application.GetOpenFilename("AD Sample Floor Excel Files (*.xlsm), *.xlsm", , "Select AD Sample Floor Excel File", , False)
        xlApp.Visible = True
        Set xlSh = xlApp.Workbooks.Open(FileToOpen)
        
        xlSh.Activate
        XClient = xlSh.Sheets("Job Details").Cells(3, 2)
        XAddress = xlSh.Sheets("Job Details").Cells(4, 2)
        XPhone = xlSh.Sheets("Job Details").Cells(7, 2)
        XEmail = xlSh.Sheets("Job Details").Cells(8, 2)
        
        SetBookmarkText ThisDocument, "Client1", XClient
        SetBookmarkText ThisDocument, "Client2", XClient
        
        SetBookmarkText ThisDocument, "Address1", XAddress
        SetBookmarkText ThisDocument, "Address2", XAddress
        
        SetBookmarkText ThisDocument, "Phone", XPhone
            
        SetBookmarkText ThisDocument, "Email", XEmail
    
    
    End Sub
    This is the error I am getting:
    Code:
    Bookmark 'Client1' not found in document
    '5555R001.XX.YYMMDD.docm'
    Content not updated
    The error repeats for 'Address1' but all the other ones update as expected.

    Thank you and have a good day!
    Last edited by jmfloyd; 4 days ago.

  • #2
    Can't you remove the TextBox?
    Hope that Helps

    Roy

    New users should read the Forum Rules before posting

    For free Excel tools & articles visit my web site

    RoyUK's Web Site

    royUK's Database Form

    Where to paste code from the Forum

    About me.

    Comment


    • #3


      Hi Roy

      The text boxes are part of my standard report which needs to be consistent. Thank you for the suggestion, but I am in need of a technical solution.

      Cheers

      Comment

      Working...
      X