<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'automating Word using VB.NET please help!!' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'automating Word using VB.NET please help!!' posted on the 'VBA' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 25 May 2013 16:54:10 -0700</pubDate>
    <lastBuildDate>Sat, 25 May 2013 16:54:10 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>automating Word using VB.NET please help!!</title>
      <link>http://www.programmersheaven.com/mb/vba/169177/169177/automating-word-using-vbnet-please-help/</link>
      <description>I'm struggling with the following: &lt;br /&gt;
&lt;br /&gt;
I'm using VB.NET and I want to make a program that put some text from a textbox at a certain place in a Word document. &lt;br /&gt;
&lt;br /&gt;
So I used the following code to start Word with a new document and a bookmark were I want to have the text from the textbox: &lt;br /&gt;
&lt;br /&gt;
**************************************************
********************* &lt;br /&gt;
Dim wordapp As Word.Application &lt;br /&gt;
Dim letter As Word.Document &lt;br /&gt;
&lt;br /&gt;
wordapp = CType(CreateObject("Word.Application"),_ &lt;br /&gt;
Word.Application) &lt;br /&gt;
brief = CType(wordapp.Documents.Add, Word.Document) &lt;br /&gt;
brief.Bookmarks.Add("mark1") &lt;br /&gt;
brief.Application.Visible = True &lt;br /&gt;
**************************************************
********************* &lt;br /&gt;
I have two questions: &lt;br /&gt;
&lt;br /&gt;
1)First of all this code creates a NEW word document, BUT I want to use an existing Word document(with already some text and pictures in it). &lt;br /&gt;
&lt;br /&gt;
2)I don't know how to put the text from the textbox at the place of the bookmark! &lt;br /&gt;
&lt;br /&gt;
I'm very new to this, so I would appreciate it you can give my the correct code for this, not only some hints. &lt;br /&gt;
&lt;br /&gt;
Hope someone can help me! &lt;br /&gt;
&lt;br /&gt;
Thanks, &lt;br /&gt;
&lt;br /&gt;
VB Newbie &lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/vba/169177/169177/automating-word-using-vbnet-please-help/</guid>
      <pubDate>Tue, 04 Feb 2003 14:19:38 -0700</pubDate>
      <category>VBA</category>
    </item>
    <item>
      <title>Re: automating Word using VB.NET please help!!</title>
      <link>http://www.programmersheaven.com/mb/vba/169177/174688/re-automating-word-using-vbnet-please-help/#174688</link>
      <description>: I'm struggling with the following: &lt;br /&gt;
: &lt;br /&gt;
: I'm using VB.NET and I want to make a program that put some text from a textbox at a certain place in a Word document. &lt;br /&gt;
: &lt;br /&gt;
: So I used the following code to start Word with a new document and a bookmark were I want to have the text from the textbox: &lt;br /&gt;
: &lt;br /&gt;
: **************************************************
********************* &lt;br /&gt;
: Dim wordapp As Word.Application &lt;br /&gt;
: Dim letter As Word.Document &lt;br /&gt;
: &lt;br /&gt;
: wordapp = CType(CreateObject("Word.Application"),_ &lt;br /&gt;
: Word.Application) &lt;br /&gt;
: brief = CType(wordapp.Documents.Add, Word.Document) &lt;br /&gt;
: brief.Bookmarks.Add("mark1") &lt;br /&gt;
: brief.Application.Visible = True &lt;br /&gt;
: **************************************************
********************* &lt;br /&gt;
: I have two questions: &lt;br /&gt;
: &lt;br /&gt;
: 1)First of all this code creates a NEW word document, BUT I want to use an existing Word document(with already some text and pictures in it). &lt;br /&gt;
: &lt;br /&gt;
: 2)I don't know how to put the text from the textbox at the place of the bookmark! &lt;br /&gt;
: &lt;br /&gt;
: I'm very new to this, so I would appreciate it you can give my the correct code for this, not only some hints. &lt;br /&gt;
: &lt;br /&gt;
: Hope someone can help me! &lt;br /&gt;
: &lt;br /&gt;
: Thanks, &lt;br /&gt;
: &lt;br /&gt;
: VB Newbie &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/vba/169177/174688/re-automating-word-using-vbnet-please-help/#174688</guid>
      <pubDate>Wed, 05 Mar 2003 14:03:48 -0700</pubDate>
      <category>VBA</category>
    </item>
    <item>
      <title>Re: automating Word using VB.NET please help!!</title>
      <link>http://www.programmersheaven.com/mb/vba/169177/174689/re-automating-word-using-vbnet-please-help/#174689</link>
      <description>: : I'm struggling with the following: &lt;br /&gt;
: : &lt;br /&gt;
: : I'm using VB.NET and I want to make a program that put some text from a textbox at a certain place in a Word document. &lt;br /&gt;
: : &lt;br /&gt;
: : So I used the following code to start Word with a new document and a bookmark were I want to have the text from the textbox: &lt;br /&gt;
: : &lt;br /&gt;
: : **************************************************
********************* &lt;br /&gt;
: : Dim wordapp As Word.Application &lt;br /&gt;
: : Dim letter As Word.Document &lt;br /&gt;
: : &lt;br /&gt;
: : wordapp = CType(CreateObject("Word.Application"),_ &lt;br /&gt;
: : Word.Application) &lt;br /&gt;
: : brief = CType(wordapp.Documents.Add, Word.Document) &lt;br /&gt;
: : brief.Bookmarks.Add("mark1") &lt;br /&gt;
: : brief.Application.Visible = True &lt;br /&gt;
: : **************************************************
********************* &lt;br /&gt;
: : I have two questions: &lt;br /&gt;
: : &lt;br /&gt;
: : 1)First of all this code creates a NEW word document, BUT I want to use an existing Word document(with already some text and pictures in it). &lt;br /&gt;
: : &lt;br /&gt;
: : 2)I don't know how to put the text from the textbox at the place of the bookmark! &lt;br /&gt;
: : &lt;br /&gt;
: : I'm very new to this, so I would appreciate it you can give my the correct code for this, not only some hints. &lt;br /&gt;
: : &lt;br /&gt;
: : Hope someone can help me! &lt;br /&gt;
: : &lt;br /&gt;
: : Thanks, &lt;br /&gt;
: : &lt;br /&gt;
: : VB Newbie &lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
This routine starts MS Word.  If its already going, then it sets it up for a new object (Document) to be opened.&lt;br /&gt;
__________________________________________________
_____________&lt;br /&gt;
Public Sub GtWord()&lt;br /&gt;
On Error Resume Next&lt;br /&gt;
Dim wdApp As Word.Application&lt;br /&gt;
' MsgBox "Start MS Word and Click OK", vbOKOnly, "Start MS Word"&lt;br /&gt;
Set wdApp = GetObject(, "Word.Application")&lt;br /&gt;
If wdApp Is Nothing Then&lt;br /&gt;
   Set wdApp = CreateObject("Word.Application")&lt;br /&gt;
   If wdApp Is Nothing Then&lt;br /&gt;
      MsgBox "Error starting MS Word - Click OK", vbOKOnly, "Start MS Word"&lt;br /&gt;
   End If&lt;br /&gt;
End If&lt;br /&gt;
wdApp.Visible = True&lt;br /&gt;
End Sub&lt;br /&gt;
__________________________________________________
_____________&lt;br /&gt;
&lt;br /&gt;
This module processes an Access MDB and replaces strings in the Document with the data from the MDB.  The big trick to using this is having a reference (Project, References).  Choose the following 2  items to process word docs:  &lt;br /&gt;
1.	Microsoft Word 9.0 Object Library&lt;br /&gt;
2.	Microsoft ActiveX Data Objects Recordset 2.6 Library&lt;br /&gt;
&lt;br /&gt;
__________________________________________________
_____________&lt;br /&gt;
Public Sub Proc1( )&lt;br /&gt;
Dim strFN1, strFN2, strFN3 As String&lt;br /&gt;
MousePointer = vbHourglass&lt;br /&gt;
Call GtWord&lt;br /&gt;
Do While Not dtaTEXARK.Recordset.EOF&lt;br /&gt;
   txtInput.Text = txtInput.Text + 1&lt;br /&gt;
   Call TheNext&lt;br /&gt;
   For intX = 0 To 7&lt;br /&gt;
    With ActiveDocument.Content.Find&lt;br /&gt;
       '  With ActiveDocument.Content.Find&lt;br /&gt;
     .Text = strArray(intX)&lt;br /&gt;
     .Replacement.Text = strRep(intX)&lt;br /&gt;
     .Forward = 1&lt;br /&gt;
     .Wrap = wdFindStop&lt;br /&gt;
     .Execute Replace:=wdReplaceAll&lt;br /&gt;
    End With&lt;br /&gt;
   Next&lt;br /&gt;
' ActiveDocument.SaveAs Mid$(strFileName, 1, 9) _&lt;br /&gt;
'  &amp;amp; "1099_ck\" &amp;amp; strRep(7) &amp;amp; ".DOC"&lt;br /&gt;
strFN1 = "D:\TX_AR\1099_ck\" &amp;amp; strRep(7) &amp;amp; ".DOC"&lt;br /&gt;
strFN2 = "D:\TX_AR\1099_ck\" &amp;amp; strRep(7) &amp;amp; "a.DOC"&lt;br /&gt;
strFN3 = "D:\TX_AR\1099_ck\" &amp;amp; strRep(7) &amp;amp; "b.DOC"&lt;br /&gt;
'  strFN1 doesn't exist, then go on&lt;br /&gt;
If Dir(strFN1) = "" Then&lt;br /&gt;
Else&lt;br /&gt;
   If Dir(strFN2) = "" Then   ' strFN1 exist but strFN2 doesn't&lt;br /&gt;
      strFN1 = strFN2&lt;br /&gt;
   Else&lt;br /&gt;
      If Dir(strFN3) = "" Then    ' strFN1 and strFN2 exist but strFN3 doesn't&lt;br /&gt;
         strFN1 = strFN3&lt;br /&gt;
      Else&lt;br /&gt;
          ' strFN1, strFN2, and strFN3 exist&lt;br /&gt;
         MsgBox "More than 3 Forms for SSN = " &amp;amp; strRep(7), vbOKOnly, "Multiple Forms"&lt;br /&gt;
      End If&lt;br /&gt;
   End If&lt;br /&gt;
End If&lt;br /&gt;
 txtOutput.Text = txtOutput.Text + 1&lt;br /&gt;
ActiveDocument.SaveAs (strFN1)&lt;br /&gt;
' ActiveDocument.PrintOut&lt;br /&gt;
ActiveDocument.Close&lt;br /&gt;
dtaTEXARK.Recordset.MoveNext&lt;br /&gt;
Loop&lt;br /&gt;
MousePointer = vbArrow&lt;br /&gt;
dtaTEXARK.Recordset.Close&lt;br /&gt;
End Sub&lt;br /&gt;
__________________________________________________
_____________&lt;br /&gt;
&lt;br /&gt;
This module determines which Document to open (STPOLICE, JUDICIAL, PUBLIC Employees) and retrieves the Data from the MDB. &lt;br /&gt;
__________________________________________________
_____________&lt;br /&gt;
Public Sub TheNext()&lt;br /&gt;
If dtaTEXARK.Recordset!Sys = "PER" Then&lt;br /&gt;
   strRep(1) = "Public Employees Retirement System"&lt;br /&gt;
   strRep(0) = "71-0385993"&lt;br /&gt;
Else&lt;br /&gt;
   If dtaTEXARK.Recordset!Sys = "JUD" Then&lt;br /&gt;
      strRep(1) = "Judicial Retirement System       "&lt;br /&gt;
      strRep(0) = "71-0578996"&lt;br /&gt;
   Else&lt;br /&gt;
      If dtaTEXARK.Recordset!Sys = "STP" Then&lt;br /&gt;
         strRep(1) = "State Police Retirement System   "&lt;br /&gt;
         strRep(0) = "71-6060127"&lt;br /&gt;
      End If&lt;br /&gt;
   End If&lt;br /&gt;
End If&lt;br /&gt;
If Len(dtaTEXARK.Recordset!Name) &amp;lt; 65 Then&lt;br /&gt;
   intZ = 65 - Len(dtaTEXARK.Recordset!Name)&lt;br /&gt;
   strRep(2) = dtaTEXARK.Recordset!Name &amp;amp; Space(intZ)&lt;br /&gt;
Else&lt;br /&gt;
   strRep(2) = dtaTEXARK.Recordset!Name&lt;br /&gt;
End If&lt;br /&gt;
If Len(dtaTEXARK.Recordset!Address) &amp;lt; 46 Then&lt;br /&gt;
   intZ = 46 - Len(dtaTEXARK.Recordset!Address)&lt;br /&gt;
   strRep(3) = dtaTEXARK.Recordset!Address &amp;amp; Space(intZ)&lt;br /&gt;
Else&lt;br /&gt;
   strRep(3) = dtaTEXARK.Recordset!Address&lt;br /&gt;
End If&lt;br /&gt;
strRep(4) = dtaTEXARK.Recordset!City &amp;amp; Space(10)&lt;br /&gt;
strRep(5) = dtaTEXARK.Recordset!Zip&lt;br /&gt;
strRep(6) = Format(dtaTEXARK.Recordset!Gross, "###,##0.00")&lt;br /&gt;
If Len(strRep(6)) &amp;lt; 10 Then&lt;br /&gt;
   intZ = 10 - Len(strRep(6))&lt;br /&gt;
   strRep(6) = Space(intZ) &amp;amp; strRep(6)&lt;br /&gt;
End If&lt;br /&gt;
strRep(7) = Mid$(dtaTEXARK.Recordset!SSN, 1, 3) &amp;amp; "-" &amp;amp; _&lt;br /&gt;
            Mid$(dtaTEXARK.Recordset!SSN, 4, 2) &amp;amp; "-" &amp;amp; _&lt;br /&gt;
            Mid$(dtaTEXARK.Recordset!SSN, 6, 4)&lt;br /&gt;
If dtaTEXARK.Recordset!State = "AR" Then&lt;br /&gt;
   strFileName = Mid$(strFileName, 1, 19) &amp;amp; "AR.DOC"&lt;br /&gt;
Else&lt;br /&gt;
   strFileName = Mid$(strFileName, 1, 19) &amp;amp; "TX.DOC"&lt;br /&gt;
End If&lt;br /&gt;
If Dir(strFileName) &amp;lt;&amp;gt; "" Then&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox "doesn't exist", vbOKOnly, "File Check Status"&lt;br /&gt;
   Exit Sub&lt;br /&gt;
End If&lt;br /&gt;
Documents.Open strFileName&lt;br /&gt;
End Sub&lt;br /&gt;
==================================================
====================&lt;br /&gt;
The Documents.Open is the syntax to open the Document.  I open a standard DOC (Texarkana_AR.DOC), replace the strings, then do a save as, Print the DOC (mine is commented out in this code), close the DOC.&lt;br /&gt;
&lt;br /&gt;
Hope this helps.&lt;br /&gt;
&lt;br /&gt;
Bob Fischer&lt;br /&gt;
DP Manager, APERS&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/vba/169177/174689/re-automating-word-using-vbnet-please-help/#174689</guid>
      <pubDate>Wed, 05 Mar 2003 14:05:56 -0700</pubDate>
      <category>VBA</category>
    </item>
  </channel>
</rss>