Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-24-2018, 07:46 PM
Guessed's Avatar
Guessed Guessed is offline Userforms and DDE Windows 10 Userforms and DDE Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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
  #2  
Old 10-25-2018, 01:55 PM
Wojix Wojix is offline Userforms and DDE Windows 7 64bit Userforms and DDE Office 2010 64bit
Novice
Userforms and DDE
 
Join Date: Apr 2018
Posts: 8
Wojix is on a distinguished road
Default

I gave the code a try, however I keep getting "Compile Error: Expected: end of statement" on this piece of code ...



Code:
set aDoc = .Documents.Add Template:="[Path to .dot file]", NewTemplate:=False
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Could somebody help me with the code of my VBA userforms(Combibox - saving - editing of data) 19339 Excel Programming 2 09-14-2018 12:06 AM
Is it possible to have menubar in userforms srinivasaru Excel Programming 3 03-22-2017 03:53 AM
using office icons on userforms controls fraz627 Excel 0 05-02-2014 06:02 PM
Userforms and DDE Multiple Userforms Displaying Different Content but Returning Same Content? marksm33 Word VBA 1 02-24-2014 06:17 PM
Userforms and DDE looping controls on userforms Cbrehm Excel Programming 5 05-11-2011 02:53 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft