<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: VBA &#8211; Word &#8211; Update/Fill-in Document Form Fields	</title>
	<atom:link href="https://www.devhut.net/vba-word-update-fill-in-document-form-fields/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.devhut.net/vba-word-update-fill-in-document-form-fields/</link>
	<description>MS Access &#38; MS Office Help, Tutorials, Samples and more ...</description>
	<lastBuildDate>Sun, 20 Nov 2022 12:05:02 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>
		By: SFF		</title>
		<link>https://www.devhut.net/vba-word-update-fill-in-document-form-fields/comment-page-1/#comment-5903</link>

		<dc:creator><![CDATA[SFF]]></dc:creator>
		<pubDate>Wed, 25 Nov 2020 07:37:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.devhut.net/?p=362#comment-5903</guid>

					<description><![CDATA[How could I use this to update all fields is an open document?]]></description>
			<content:encoded><![CDATA[<p>How could I use this to update all fields is an open document?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Cleo Bis		</title>
		<link>https://www.devhut.net/vba-word-update-fill-in-document-form-fields/comment-page-1/#comment-3355</link>

		<dc:creator><![CDATA[Cleo Bis]]></dc:creator>
		<pubDate>Fri, 01 May 2020 19:15:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.devhut.net/?p=362#comment-3355</guid>

					<description><![CDATA[Bookmarked!, I love your blog!]]></description>
			<content:encoded><![CDATA[<p>Bookmarked!, I love your blog!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Kamala Authur		</title>
		<link>https://www.devhut.net/vba-word-update-fill-in-document-form-fields/comment-page-1/#comment-3345</link>

		<dc:creator><![CDATA[Kamala Authur]]></dc:creator>
		<pubDate>Thu, 30 Apr 2020 22:20:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.devhut.net/?p=362#comment-3345</guid>

					<description><![CDATA[Saved as a favorite!, I really like your website!]]></description>
			<content:encoded><![CDATA[<p>Saved as a favorite!, I really like your website!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Alberto		</title>
		<link>https://www.devhut.net/vba-word-update-fill-in-document-form-fields/comment-page-1/#comment-1897</link>

		<dc:creator><![CDATA[Alberto]]></dc:creator>
		<pubDate>Fri, 02 Mar 2018 22:58:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.devhut.net/?p=362#comment-1897</guid>

					<description><![CDATA[Wonderful!
Thank you!

I&#039;ve adjusted the code for my purpose, I have to retrieve the last row of an excel and fill the template word, then save with another name.
I&#039;ve figured that word file is opened every two times, not always
first click --&#062; open word
then I close word
click again on the macro button --&#062; open word, open file, filling text, save file renamed, everything ok
then I close everything
next time the same...
first click --&#062; ...

this is my code, any tips &#038; tricks??

Sub UpdateDoc()
&#039;Requires a reference to the Word object library
Dim oApp        As Object &#039;Word.Application
Dim oDoc        As Object &#039;Word.Document
Dim sDocName    As String
 
On Error Resume Next
    Set oApp = GetObject(, &quot;Word.Application&quot;) &#039;See if word is already running
    If Err.Number  0 Then     &#039;Word isn&#039;t running so start it
        Set oApp = CreateObject(&quot;Word.Application&quot;)
    End If
 
On Error GoTo Error_Handler_Exit
    
    sDocName = (ThisWorkbook.Path &#038; &quot;/modello_offerta.dotx&quot;)
    Set oDoc = oApp.Documents.Add(sDocName)
    oApp.Visible = True
 
    LastRow = ThisWorkbook.Sheets(&quot;Offerte&quot;).Cells.SpecialCells(xlCellTypeLastCell).Row
 
    oDoc.FormFields(&quot;Numero_Offerta&quot;).Result = ThisWorkbook.Sheets(&quot;Offerte&quot;).Range(&quot;A&quot; &#038; LastRow).Value    &#039;Textbox
    oDoc.FormFields(&quot;Name&quot;).Result = ThisWorkbook.Sheets(&quot;Offerte&quot;).Range(&quot;B&quot; &#038; LastRow).Value     &#039;Textbox
    &#039;oDoc.FormFields(&quot;CheckboxName&quot;).CheckBox.Value = True   &#039;Checkbox
    
    With oDoc

    oDoc.SaveAs FileName:=(ThisWorkbook.Path &#038; &quot;/offerte/&quot; &#038; oDoc.FormFields(&quot;Numero_Offerta&quot;).Result &#038; &quot;_&quot; &#038; oDoc.FormFields(&quot;Name&quot;).Result &#038; &quot;.docx&quot;)
    
    End With
 
Error_Handler_Exit:
    On Error Resume Next
    &#039;oDoc.Close True
    &#039;oApp.Quit
    Set oDoc = Nothing
    Set oApp = Nothing
    Exit Sub
 
Error_Handler:
    If Err.Number = 5174 Then
        MsgBox &quot;The specified file &#039;&quot; &#038; sDocName &#038; &quot;&#039; could not be found.&quot;, _
               vbCritical
    Else
        MsgBox &quot;The following error has occured.&quot; &#038; vbCrLf &#038; vbCrLf &#038; _
               &quot;Error Number: &quot; &#038; Err.Number &#038; vbCrLf &#038; _
               &quot;Error Source: UpdateDoc&quot; &#038; vbCrLf &#038; _
               &quot;Error Description: &quot; &#038; Err.Description, _
               vbCritical, &quot;An Error has Occured!&quot;
    End If
    Resume Error_Handler_Exit
End Sub]]></description>
			<content:encoded><![CDATA[<p>Wonderful!<br />
Thank you!</p>
<p>I&#8217;ve adjusted the code for my purpose, I have to retrieve the last row of an excel and fill the template word, then save with another name.<br />
I&#8217;ve figured that word file is opened every two times, not always<br />
first click &#8211;&gt; open word<br />
then I close word<br />
click again on the macro button &#8211;&gt; open word, open file, filling text, save file renamed, everything ok<br />
then I close everything<br />
next time the same&#8230;<br />
first click &#8211;&gt; &#8230;</p>
<p>this is my code, any tips &amp; tricks??</p>
<p>Sub UpdateDoc()<br />
&#8216;Requires a reference to the Word object library<br />
Dim oApp        As Object &#8216;Word.Application<br />
Dim oDoc        As Object &#8216;Word.Document<br />
Dim sDocName    As String</p>
<p>On Error Resume Next<br />
    Set oApp = GetObject(, &#8220;Word.Application&#8221;) &#8216;See if word is already running<br />
    If Err.Number  0 Then     &#8216;Word isn&#8217;t running so start it<br />
        Set oApp = CreateObject(&#8220;Word.Application&#8221;)<br />
    End If</p>
<p>On Error GoTo Error_Handler_Exit</p>
<p>    sDocName = (ThisWorkbook.Path &amp; &#8220;/modello_offerta.dotx&#8221;)<br />
    Set oDoc = oApp.Documents.Add(sDocName)<br />
    oApp.Visible = True</p>
<p>    LastRow = ThisWorkbook.Sheets(&#8220;Offerte&#8221;).Cells.SpecialCells(xlCellTypeLastCell).Row</p>
<p>    oDoc.FormFields(&#8220;Numero_Offerta&#8221;).Result = ThisWorkbook.Sheets(&#8220;Offerte&#8221;).Range(&#8220;A&#8221; &amp; LastRow).Value    &#8216;Textbox<br />
    oDoc.FormFields(&#8220;Name&#8221;).Result = ThisWorkbook.Sheets(&#8220;Offerte&#8221;).Range(&#8220;B&#8221; &amp; LastRow).Value     &#8216;Textbox<br />
    &#8216;oDoc.FormFields(&#8220;CheckboxName&#8221;).CheckBox.Value = True   &#8216;Checkbox</p>
<p>    With oDoc</p>
<p>    oDoc.SaveAs FileName:=(ThisWorkbook.Path &amp; &#8220;/offerte/&#8221; &amp; oDoc.FormFields(&#8220;Numero_Offerta&#8221;).Result &amp; &#8220;_&#8221; &amp; oDoc.FormFields(&#8220;Name&#8221;).Result &amp; &#8220;.docx&#8221;)</p>
<p>    End With</p>
<p>Error_Handler_Exit:<br />
    On Error Resume Next<br />
    &#8216;oDoc.Close True<br />
    &#8216;oApp.Quit<br />
    Set oDoc = Nothing<br />
    Set oApp = Nothing<br />
    Exit Sub</p>
<p>Error_Handler:<br />
    If Err.Number = 5174 Then<br />
        MsgBox &#8220;The specified file &#8216;&#8221; &amp; sDocName &amp; &#8220;&#8216; could not be found.&#8221;, _<br />
               vbCritical<br />
    Else<br />
        MsgBox &#8220;The following error has occured.&#8221; &amp; vbCrLf &amp; vbCrLf &amp; _<br />
               &#8220;Error Number: &#8221; &amp; Err.Number &amp; vbCrLf &amp; _<br />
               &#8220;Error Source: UpdateDoc&#8221; &amp; vbCrLf &amp; _<br />
               &#8220;Error Description: &#8221; &amp; Err.Description, _<br />
               vbCritical, &#8220;An Error has Occured!&#8221;<br />
    End If<br />
    Resume Error_Handler_Exit<br />
End Sub</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: admin		</title>
		<link>https://www.devhut.net/vba-word-update-fill-in-document-form-fields/comment-page-1/#comment-432</link>

		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 10 Jan 2013 00:59:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.devhut.net/?p=362#comment-432</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.devhut.net/vba-word-update-fill-in-document-form-fields/comment-page-1/#comment-431&quot;&gt;MikeC&lt;/a&gt;.

My tests all worked fine with Access and Word 2010 so I suspect something else is going on.

Also, to get the count your synthax should be: oDoc.FormFields.count]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.devhut.net/vba-word-update-fill-in-document-form-fields/comment-page-1/#comment-431">MikeC</a>.</p>
<p>My tests all worked fine with Access and Word 2010 so I suspect something else is going on.</p>
<p>Also, to get the count your synthax should be: oDoc.FormFields.count</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: MikeC		</title>
		<link>https://www.devhut.net/vba-word-update-fill-in-document-form-fields/comment-page-1/#comment-431</link>

		<dc:creator><![CDATA[MikeC]]></dc:creator>
		<pubDate>Wed, 09 Jan 2013 17:31:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.devhut.net/?p=362#comment-431</guid>

					<description><![CDATA[The oDoc.FormFields(&quot;MyFieldName&quot;) form field references do not appear to work in Word 2010.  In fact, the below line of code returns a count of zero.

Debug.Print ActiveDocument.FormFields.Count

Is there a way to use VBA to update and manipulate form fields in Word 2010 or has Microsoft abandoned us?]]></description>
			<content:encoded><![CDATA[<p>The oDoc.FormFields(&#8220;MyFieldName&#8221;) form field references do not appear to work in Word 2010.  In fact, the below line of code returns a count of zero.</p>
<p>Debug.Print ActiveDocument.FormFields.Count</p>
<p>Is there a way to use VBA to update and manipulate form fields in Word 2010 or has Microsoft abandoned us?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Esther		</title>
		<link>https://www.devhut.net/vba-word-update-fill-in-document-form-fields/comment-page-1/#comment-380</link>

		<dc:creator><![CDATA[Esther]]></dc:creator>
		<pubDate>Tue, 28 Aug 2012 11:34:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.devhut.net/?p=362#comment-380</guid>

					<description><![CDATA[Thaaaaanks!!

You have just save my life.

Best regards, 

Esther]]></description>
			<content:encoded><![CDATA[<p>Thaaaaanks!!</p>
<p>You have just save my life.</p>
<p>Best regards, </p>
<p>Esther</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
