Results 1 to 4 of 4

Thread: Getting text from Excel to Word

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,273
    Location
    Before clearing the userform (e.g. immediately before or after 'sh.Protect "1078"'), you might use code like:
    'declare variables for word
    Dim wdApp As New Word.Application
    Dim wdDoc As Word.Document
    wdApp.Visible = True
    
    'add a new word document
    Set wdDoc = wdApp.Documents.Add(Template:="complaint document template")
    
    'update the document
    With wdDoc
      .Bookmarks("Datum").Range.Text = Me.txtDatum.Value
      .Bookmarks("Manager").Range.Text = Me.txtManager.Value
      .Bookmarks("GStele").Range.Text = Me.cboGStele.Value
      .Bookmarks("Voornaam").Range.Text = Me.txtVoornaam.Value
      .Bookmarks("Achternaam").Range.Text = Me.txtAchternaam.Value
      .Bookmarks("Adres").Range.Text = Me.txtAdres.Value
      .Bookmarks("Postcode").Range.Text = Me.txtPostcode.Value
      .Bookmarks("Nummer").Range.Text = Me.txtNummer.Value
      .Bookmarks("Verkeerd").Range.Text = Me.txtVerkeerd.Value
      .Bookmarks("Vergoeding").Range.Text = Me.cboVergoeding.Value
      .Bookmarks("MeneerMevrouw").Range.Text = Me.cboMeneerMevrouw.Value
    End With
    Do note that the above code assumes the use of early binding, so you will need to set a reference to Word via the VBE's Tools>References. You will also need to supply the full path & name for your complaint document template where I've inserted "complaint document template".


    PS: When posting code, please format it and use the code tags. Without both, you code is much harder to read than it need be.
    Last edited by macropod; 08-07-2018 at 04:14 PM.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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