Onamission71
Member
- Joined
- Jul 8, 2009
- Messages
- 14
- Programming Experience
- Beginner
Hi, hope someone can help, I have a windows form with one textbox and one button (this is just until i get it working, then there will be more) basically I want to add the text press the button and this will open a Word template and populate a space in a sentence within that template.
code so far:-
Imports Word = Microsoft.Office.Interop.Word
Imports office = Microsoft.Office.Core
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim location As String
Dim oWord As Word.Application
Dim oDoc As Word.Document
location = TextBox1.Text
'Start Word and Open document template
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add("C:\test.dotx")
oDoc.Bookmarks("mybookmark").Range.Text = location
End Sub
End Class
This opens the template but where I have created the bookmark in the word document I get Error! bookmark not defined. Am I creating the bookmark wrong or is it my code? How should I create the bookmark.?
code so far:-
Imports Word = Microsoft.Office.Interop.Word
Imports office = Microsoft.Office.Core
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim location As String
Dim oWord As Word.Application
Dim oDoc As Word.Document
location = TextBox1.Text
'Start Word and Open document template
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add("C:\test.dotx")
oDoc.Bookmarks("mybookmark").Range.Text = location
End Sub
End Class
This opens the template but where I have created the bookmark in the word document I get Error! bookmark not defined. Am I creating the bookmark wrong or is it my code? How should I create the bookmark.?