View Single Post
 
Old 10-18-2018, 06:24 AM
Wojix Wojix is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Apr 2018
Posts: 8
Wojix is on a distinguished road
Default

Here's the code for excel:


Code:
Sub Open_Word_Doc()

    Dim WRD As Object
    On Error Resume Next
    Set WRD = GetObject(, "Word.Application")
    If Err.Number Then
      Err.Clear
      Set WRD = CreateObject("Word.Application")
    End If

    WRD.Visible = True
    WRD.Application.WindowState = wdWindowStateMaximize
    WRD.Application.ScreenUpdating = True
    WRD.Activate
    WRD.Documents.Add Template:= _
          "[Path to .dot file]", _
                NewTemplate:=False

    WRD.Selection.WholeStory
    WRD.Selection.Fields.Update
    WRD.Selection.HomeKey Unit:=wdStory
    WRD.Application.ScreenUpdating = True

    Set WRD = Nothing

 End Sub
In my Word Template, I have this in the field code:


Code:
{Set "Width" "{DDE Excel "[Path to .xls file]" [Cell Name] \t \* mergeformat}"}
I also have this VBA code in Word:


Code:
Sub AutoNew()
Create_Reset_Variables
CallUF
End Sub
Code:
Sub CallUF()
Dim oFrm As WrdFrm
    Set oFrm = New WrdFrm
        With oFrm
            .Show
    End With
    Unload oFrm
    Set oFrm = Nothing
lbl_Exit:
    Exit Sub
End Sub
Reply With Quote