Opening Excel template from Word

S

Steve C

I have set up a macro button in a Word document that, when clicked, needs to
open a new Excel document based on an existing Excel template. The Excel
template has an opening userform that prompts the user for various
information, and when OK is clicked, distributes that info into the
spreadsheet.

Using the code below, I am able to open the Excel template as desired, along
with the userform. However, after filling out the form and clicking OK, none
of the form contents get distributed into the spreadsheet. It's as if the
click-event for the OK button is not firing. I should add that the Excel
template works perfectly if performed in Excel. Can someone help correct my
code? Thanks!

Sub CreateExcelDoc() 'creates new Excel document based on Excel template

Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True

Set xlWB = xlApp.Workbooks.Open("F:\Templates\ExcelTemplate.xlt")

Workbooks.Add(Template:= _
"F:\Word Templates\ExcelTemplate.xlt").RunAutoMacros _
Which:=xlAutoOpen

Set xlWB = Nothing
Set xlApp = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top