1
votes

Platform: Windows and Microsoft Visual Basic 2010 Express

The problem: I have a Word template made in Word 2007. When the application is run in a machine with Word 2010, the SaveAs-command doesn't work. It works fine to open a template and add data and even a photo to bookmarks in the template.

Here is the statement that doesn't work(vPath contains path and filename.):

oDoc.SaveAs(vPath.ToString)

I have tried different solution but nothing works:

oDoc.SaveAs(vPath.ToString, WdSaveFormat.wdFormatDocument)
oDoc.SaveAs(vPath.ToString, 17)  ' WdSaveFormat.wdFormatPDF
oDoc.SaveAs(vPath.ToString, 6)   ' WdSaveFormat.wdFormatRTF

References:

  • Microsoft Office 12.0 Object Library
  • Microsoft Word 12.0 Object Library

Import statements:

Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Word
1

1 Answers

2
votes

I am using Office 14 and downloaded a 2007 template. The following code works for me.

Imports Microsoft.Office.Interop
....
Dim objApp As Word.Application
Dim objDoc As Word.Document
objApp = New Word.Application()
objDoc = objApp.Documents.Open("c:\delme\templateoriginal.dotx")
objDoc.Activate()
objApp.Selection.TypeText("some text")
objDoc.SaveAs("c:\delme\template.dotx")
objDoc.Close()
objApp.Quit()
objDoc = Nothing
objApp = Nothing

Did you check that your vPath is correct? I am not sure what vPath is, but ToString is a method right so are you missing parenthesis by chance?

vPath.ToString -> vPath.ToSring()