View Single Post
 
Old 07-12-2016, 09:11 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You can do this either from Excel or from Word. Which is better rather depends on what you propose the users are going to do with the worksheet. If they are not making changes to the worksheet but merely making selections in a userform from data on the worksheet, then I would do it all in Word. If they are making changes to the worksheet and creating a document based on those changes, then I would do it in Excel. Either way you create a document from your template and write values to it from the worksheet (or based on the worksheet).

There are two functions available from my web site that will help. The xlFillList function at http://www.gmayor.com/Userform_ComboBox.html will read the worksheet into a userform list box or combo box from where a user can make suggestions. The box in question will be multi column so all the data required from each record is in the box, so you can process the selected record from the data in the columns of the box.

The other function is the FillBM function at http://www.gmayor.com/useful_vba_functions.htm which can be used to write a value from the userform to a bookmark in the document.

Working from Excel, you can read the values directly from the worksheet, but the fillBM function will need modifying to work with the specific document you are creating and not ActiveDocument.

The code to create a document from Excel would be

Code:
Dim wdApp As Object
Dim wdDoc As Object
    On Error Resume Next
    Set wdApp = GetObject(, "Word.Application")
    If Err Then
        Set wdApp = CreateObject("Word.Application")
    End If
    On Error GoTo 0
    Set wdDoc = wdApp.Documents.Add(Template:="C:\Path\TemplateName.dotx")
    'Do stuff with wdDoc
The bigger problem is how the users are going to have access to the worksheet, and the template in order to create the document.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote