View Single Post
 
Old 10-24-2018, 07:46 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,158
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I think you are trying to do have the work in Excel and half in Word. For simplicity it would be easiest to do all this in Excel and not bother with running code in Word itself (unless those same macros need to be run independent of this at other times in Word)

What if the Excel code was rewritten to
Code:
Sub Open_Word_Doc()
    Dim WRD As Object, aDoc as object
    On Error Resume Next
    Set WRD = GetObject(, "Word.Application")
    If Err.Number Then
      Err.Clear
      Set WRD = CreateObject("Word.Application")
    End If
    On Error GoTo 0
    With WRD
      .Visible = True
      .Application.WindowState = wdWindowStateMaximize
      .Application.ScreenUpdating = True
      set aDoc = .Documents.Add Template:="[Path to .dot file]", NewTemplate:=False
      With aDoc.Variables
        .Item("varAuth").Value = "None"
        .Item("varProjNum").Value = "0"
        .Item("varProjName").Value = "None"
        .Item("varDefl").Value = 0
      End With
      aDoc.Bookmarks("Width").Range.Text = ActiveWorkbook.Sheets(1).Cells(1,1).Value
      
      ''If you need to also call a userform to provide more parameters to pass into Word, do it here using a userform created in Excel

      aDoc.Range.Fields.Update
    End With
    Set aDoc = Nothing
    Set WRD = Nothing
 End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote