+ Reply to Thread
Results 1 to 2 of 2

How to transfer specific data from a excel userform to a word template

  1. #1
    Registered User
    Join Date
    11-28-2020
    Location
    The netherlands
    MS-Off Ver
    10
    Posts
    1

    How to transfer specific data from a excel userform to a word template

    For my work I need to register complaints in an excel database and then I need to enter the same data in a complaint form in words. I am new at VBA and followed a youtube tutorial to build a userform to transfer entered data to the database, but now I want to add a cmd button to transfer the same data to the word complaint form. How can I do this, I am stuck? I found this but it does not transfer the data to the bookmark.

    'Declare obj variables for the word application and document.
    Dim WdApp As Object, wdDoc As Object, wdRng As Object

    Private Sub PSave_Click()
    'Declare a String variable for the example document's name and folder path.
    Dim strDocName As String
    'On Error statement if Word is not already open.
    On Error Resume Next
    'Activate Word if it is already open.
    Set WdApp = GetObject(, "Word.Application")
    If Err.Number = 429 Then
    Err.Clear
    'Create a Word application if Word is not already open.
    Set WdApp = CreateObject("Word.Application")
    End If
    'Make sure the Word application is visible.
    WdApp.Visible = True
    'Define the strDocName String variable.
    strDocName = "C:\Users\Jasmijn\Desktop\FOR-3711 afwijkingenformulier blanco 190520-2021.docx"
    'Check the directory for the presence of the document name in the folder path.
    'If it is not recognized, inform the user and exit the macro.
    If Dir(strDocName) = "" Then
    MsgBox "The file UC372" & vbCrLf & _
    "was not found in the folder path" & vbCrLf & strDocName, _
    vbExclamation, _
    "Sorry, that document name does not exist."
    Exit Sub
    End If
    'Create the Word document from the template.
    Set wdDoc = WdApp.Documents.Add(strDocName)
    'Populate the Word document's bookmarks.
    Call UpdateBookmark("Klachtcode", frmForm.txtKlachtcode.Value)
    Call UpdateBookmark("Datum", frmForm.txtIndienerklacht.Value)
    'Update the Word document's cross-references.
    wdDoc.Fields.Update
    'Release system memory that was reserved for the Object variables.
    Set wdRng = Nothing: Set wdDoc = Nothing: Set WdApp = Nothing
    End Sub

    Sub UpdateBookmark(strBkMk As String, strTxt As String)
    With wdDoc
    If .Bookmarks.Exists(strBkMk) Then
    Set wdRng = .Bookmarks(strBkMk).Range
    wdRng.Text = strTxt
    .Bookmarks.Add strBkMk, wdRng
    End If
    End With
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: How to transfer specific data from a excel userform to a word template

    this might help to get you going

    https://www.youtube.com/watch?v=212o...nel=AndrewFant

    Best add code tags to your post by clicking the # in the toolbar
    Please be as complete as possible in your asking so it may save use all the time to rework the solution because you didn't give all the requirements. If you have a layout in mind please work it out first so we can adapt our solution to it. Thanks.
    If you have been helped, maybe you could click the *

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Transfer excel data to word template
    By Maryam11 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-17-2017, 02:26 AM
  2. [SOLVED] Export UserForm CheckBox data to Word-template
    By ODeveloper in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-21-2015, 05:25 AM
  3. Send Data From Excel Userform to Microsoft Word Document Template
    By t0mps in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-09-2014, 03:18 PM
  4. Transfer data from UserForm to Specific Sheet...
    By z-eighty2 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-07-2013, 10:26 PM
  5. Macro to open a preformatted word doc and transfer excel specific row data
    By Jhansen5452 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-08-2012, 08:19 PM
  6. Transfer EXCEL cells to WORD TEMPLATE
    By taimysho0 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 11-21-2011, 06:08 PM
  7. Transfer specific data on specific worksheet using userform
    By kriscar_44 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-17-2010, 04:03 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1