2 Replies - 14069 Views - Last Post: 21 May 2014 - 04:24 AM Rate Topic: -----

#1 gram999  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 89
  • Joined: 21-January 08

Opening an existing MS-Word Template using VB.Net

Posted 17 July 2008 - 12:31 PM

I am playing around with some code that will write text from textboxes to bookmarks on an MS Word template. I have been successful in using similar code to create word documents and write to bookmarks but for some reason I cannot get the template call correct for Word 2007 . Here is my code:


Imports Microsoft.Office.Interop

Public Class Form1

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

		Dim oWord As Word.Application
		Dim oDoc As Word.Document
		
	   
		oWord = CreateObject("Word.Application")
		oWord.Visible = True
		oDoc = oWord.Documents.Add("C:\Documents And Settings\user\Word Template.dotx ")
		
		oDoc.Bookmarks("Number1").Range.Text = TextBox1.Text
	  
		oDoc.Bookmarks("Number2").Range.Text = TextBox2.Text
			
		Me.Hide()

	End Sub
End Class




As note above I am running MS Word 2007 and VB.Net Express. The code is throwing the following error on the line where I am trying to access the location of the template: "Check the error property code of the exception to determin the HRESULT returned by the COM object." All suggestions are welcome! Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Opening an existing MS-Word Template using VB.Net

#2 gram999  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 89
  • Joined: 21-January 08

Re: Opening an existing MS-Word Template using VB.Net

Posted 17 July 2008 - 01:23 PM

False alarm. I figured it out. I was missing a folder reference in the path. It works like a charm now.
Was This Post Helpful? 0
  • +
  • -

#3 xenmei  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-May 14

Re: Opening an existing MS-Word Template using VB.Net

Posted 21 May 2014 - 04:24 AM

I AM SO HAPPY TO FIND YOUR POST! :D *shouts for joy*


thank youuuuuuuu very much! :001_icon16:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1