Search code examples
vbaoutlookms-wordoffice-automationword-contentcontrol

How can I extract and use the value from a Word rich text content control in Outlook VBA?


I want to print a number of pages which depends on the number filled in in a Word content control. I tried referring to the object with this:

Set objCC = xFileName.SelectContentControlsByTag("q_179").Item(1)
   
    Total = objCC
    Counter = 0
    Do
        Counter = Counter + 1
        xFolderItem.InvokeVerbEx ("print")
    Loop While Counter < Total

Does anyone know a solution or spot something I'm missing in the code? If you need more info lmk!

Click here to view full code


Solution

  • I'm now using this, it didn't work before because the content control is inside a table. Thanks @jonsson for your answer!

    counter = 0
    ccvalue = CInt(objWordDocument.SelectContentControlsByTag("q_179").Item(1).Range.Text)
    For Each Table In objWordDocument.Tables
      Do
          counter = counter + 1
          xFolderItem.InvokeVerbEx ("print")
          Excel.Application.Wait (Now + TimeValue("00:00:01"))
      Loop While counter < ccvalue
    Next