
Opening an Excel template from within Word VBA
Hi Rick,
Before opening or creating new files, you'll need to have a objectvariable
which contains the Excel application. Try some code like:
---------------------------------------------
Sub StartExcel()
Dim oExcel As Excel.Application
On Error Resume Next
Set oExcel = GetObject(, "Excel.Application")
If Err <> 0 Then
Set oExcel = CreateObject("Excel.application")
End If
With oExcel
.Visible = True
.Workbooks.Add Template:="Path and templatename"
End With
Set oExcel = Nothing
End Sub
---------------------------------------------
Hope this helps,
regards,
Astrid
So that all can benefit from the discussion, please post all follow-ups to
the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/
Quote:
> I have some automation to MS Word 2000 for creating faxes, etc from
> templates. I now need be able to open an Excel template from with the
Word
> VBA program but have been unsuccessful. I added the Excel 9.0 reference
to
> the Word VBA project and am trying to use the following line of code to
open
> the spreadsheet...
> Excel.Workbooks.Open (strPath & "\SomeSpreadsheet.xlt")
> This line runs without generating any errors however I never see the Excel
> template.
> Also, I want to open the template as a new spreadsheet rather than
> opening the original .XLT file for editing. I've done this with word
> templates using the following code but I'm unsure how to perform the same
> operation on an Excel template instead...
> Documents.Add Template:=strPath & "\SomeWordTemplate.DOT",
> newtemplate:=False, DocumentType:=0
> Any info would be greatly appreciated.
> Rick