Pergunta

I have been working with excel for a bit, but I have a few questions/problems I am facing in Word automation. I currently would like to format a word file dynamically on the fly. The code below is supposed to open an existing file and make changes to two different tables on the same page.

I would like to know how to either add a checkbox from the insert menu dynamically into a table cell, or change the checked state of an already existing checkbox in the table cell. Thanks for any suggestions! Its set to write text values right now, but this is for example until this is figured out..

    Dim oWord = New Microsoft.Office.Interop.Word.Application
    Dim Dir As String = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
    oWord.Documents.Open(Dir & "\welcomeletter.docx")
    Dim oDoc = oWord.ActiveDocument

    oWord.Visible = True

    Dim tbl As Word.Table = oDoc.Tables(1)

    tbl.Cell(1, 1).Range.Text = "Checkbox1"
    tbl.Cell(2, 1).Range.Text = "Checkbox2"

    Dim tbl2 As Word.Table = oDoc.Tables(2)

    tbl2.Cell(1, 1).Range.Text = "Checkbox3"
Foi útil?

Solução

To those seeking an answer, for me was to just use wingdings font and insert a checked box into the fields i require:

tbl2.Cell(1, 1).Range.Text = chw(253) etc.

I could not find anything on actually editing the checkbox.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top