Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Ok Continuint my venture I learned it would be easier to use a template this the problem I created a bookmark within my template. I can get the template open but where the bookmark is I can not get the data from a textbox in my program to show. What am I doing wrong hee is my code:

VB
               Dim oWord As Microsoft.Office.Interop.Word.Application
               Dim oDoc As Microsoft.Office.Interop.Word.Document

'Start word Document template
        oWord = CreateObject("Word.Application")
        oWord.Visible = True
        oDoc = oWord.Documents.Add("C:\Program Files\QC7\Field Quality Report.dotm")

        oDoc.Bookmarks.Item("District").Range.Text = Customer_Data.CustomerTextBox.Text

        oDoc = Nothing
        oWord = Nothing
        GC.Collect()
        GC.WaitForPendingFinalizers()
        GC.Collect()
        GC.WaitForPendingFinalizers()


        'All done
        Me.Hide()
Posted

1 solution

Its pretty straight forward, you just forgot to add some nessecary code:
http://msdn.microsoft.com/en-us/library/ad6ks7k0%28v=vs.80%29.aspx[^]

C#
object rng = bookmark.Range;
string bookmarkName = bookmark.Name;

bookmark.Range.Text = newText;

this.Bookmarks.Add(bookmarkName, ref rng);
 
Share this answer
 
v2
Comments
icecode 18-Aug-12 18:40pm    
I am sorry I just dont see the line of code I am missing in that document
icecode 18-Aug-12 20:25pm    
I just dont get it nothing seems to be working can you please evaluate my code :
Private Sub PrintDoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintDoc.Click
Dim oWord As Microsoft.Office.Interop.Word.Application
Dim oDoc As Microsoft.Office.Interop.Word.Document
Dim oRng As Microsoft.Office.Interop.Word.Range


'Start word Document template
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add("C:\Program Files\QC7\Field Quality Report.dotm")
oRng = oDoc.Bookmarks.Item("\District").Range

oRng.Bookmarks.Item("District").Range.Text = Customer_Data.CustomerTextBox.Text

oDoc = Nothing
oWord = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()


'All done
Me.Hide()



End Sub
icecode 20-Aug-12 17:50pm    
Never mind got it thank you for your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900