[Solved] Exporting: TextBox to Word

  • I have used snippits of the replies from the forum to open a fax template in Word, so all I need to do is copy the text in several Excel userform textboxes to the fields in the word template. I am using Excel 97. I am new to Word VBA.
    Do I need to create bookmarks in the word document and reference them from the Excel VBA code?
    Any example code would be appreciated.


    Thanks,
    pojic.

  • Found the solution @ Experts Exchange:


    Dim r As Range
    Dim w As Word.Application
    Dim wd As Word.Document
    Set ExcelApp = New Excel.Application
    Set ExcelWB = ExcelApp.Workbooks.Open("C:\Documents and Settings\rsimonetti\Mis documentos\centros_dir.xls")
    Set ExcelSH = ExcelWB.Sheets(1)
    Set w = New Word.Application
    Set wd = w.Documents.Open("c:\a_project\template_centros.doc")


    ExcelApp.Visible = True
    w.Visible = True
    Dim i As Integer
    For i = 2 To 10 ' this asumes that there are 8 rows where to get data
    For Each r In ExcelSH.Rows(i)
    With wd.Bookmarks("Centro")
    .Range = r.Cells(1, 1).Value
    End With
    With wd.Bookmarks("Direccion")
    .Range = r.Cells(1, 2).Value
    End With
    With wd.Bookmarks("City")
    .Range = r.Cells(1, 3).Value
    End With
    With wd.Bookmarks("state")
    .Range = r.Cells(1, 4).Value
    End With
    Next
    Next i

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!