{"id":25,"date":"2009-01-15T19:36:48","date_gmt":"2009-01-16T00:36:48","guid":{"rendered":"http:\/\/www.vodasys.net\/?p=25"},"modified":"2012-04-24T14:11:13","modified_gmt":"2012-04-24T19:11:13","slug":"microsoft-word-macro-with-user-prompts-to-fill-in-bookmarks","status":"publish","type":"post","link":"https:\/\/www.vodasys.net\/?p=25","title":{"rendered":"Microsoft Word Macro with User Prompts to Fill in Bookmarks"},"content":{"rendered":"<p>Let&#8217;s say you have a Microsoft Word document and you want to write a Macro that will:<\/p>\n<ul>\n<li>Start upon opening<\/li>\n<li>Prompt the user for input<\/li>\n<li>Put the inputted data in specific places on your document<\/li>\n<li>Print the document.<\/li>\n<\/ul>\n<p>Here is the Macro Code:<\/p>\n<p><span style=\"color: #0000ff;\">Private Sub Document_Open()<\/span><\/p>\n<p>Dim custpartno As String<br \/>\nDim ourpartno As String<br \/>\nDim rev As String<br \/>\nDim releaseqty As String<br \/>\nDim ponumber As String<\/p>\n<p>custpartno = InputBox(&#8220;Enter Customer Part Number:&#8221;)<br \/>\nIf Len(custpartno) = 0 Then Exit Sub &#8216; user canceled<br \/>\nActiveDocument.Bookmarks(&#8220;CustomerPartNumber&#8221;).Range.Text = custpartno<\/p>\n<p>ourpartno = InputBox(&#8220;Enter Our Part Number:&#8221;)<br \/>\nIf Len(ourpartno) = 0 Then Exit Sub &#8216; user canceled<br \/>\nActiveDocument.Bookmarks(&#8220;OurPartNumber&#8221;).Range.Text = ourpartno<\/p>\n<p>rev = InputBox(&#8220;Enter Revision:&#8221;)<br \/>\nIf Len(rev) = 0 Then Exit Sub &#8216; user canceled<br \/>\nActiveDocument.Bookmarks(&#8220;revision&#8221;).Range.Text = rev<\/p>\n<p>qty = InputBox(&#8220;Enter Quantity:&#8221;)<br \/>\nIf Len(qty) = 0 Then Exit Sub &#8216; user canceled<br \/>\nActiveDocument.Bookmarks(&#8220;Quantity&#8221;).Range.Text = releaseqty<\/p>\n<p>ponumber = InputBox(&#8220;Enter Purchase Order:&#8221;)<br \/>\nIf Len(ponumber) = 0 Then Exit Sub &#8216; user canceled<br \/>\nActiveDocument.Bookmarks(&#8220;PurchaseOrder&#8221;).Range.Text = ponumber<\/p>\n<p>Application.PrintOut FileName:=&#8221;&#8221;, Range:=wdPrintAllDocument, Item:= _<br \/>\nwdPrintDocumentContent, Copies:=1, Pages:=&#8221;&#8221;, PageType:=wdPrintAllPages, _<br \/>\nManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _<br \/>\nFalse, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _<br \/>\nPrintZoomPaperHeight:=0<\/p>\n<p>MsgBox &#8220;Press Any Key to Exit.&#8221;<\/p>\n<p>Application.Quit SaveChanges:=False<\/p>\n<p><span style=\"color: #0000ff;\">End Sub<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s say you have a Microsoft Word document and you want to write a Macro that will: Start upon opening Prompt the user for input Put the inputted data in specific places on your document Print the document. Here is the Macro Code: Private Sub Document_Open() Dim custpartno As String Dim ourpartno As String Dim &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.vodasys.net\/?p=25\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Microsoft Word Macro with User Prompts to Fill in Bookmarks&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.vodasys.net\/index.php?rest_route=\/wp\/v2\/posts\/25"}],"collection":[{"href":"https:\/\/www.vodasys.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vodasys.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vodasys.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vodasys.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=25"}],"version-history":[{"count":4,"href":"https:\/\/www.vodasys.net\/index.php?rest_route=\/wp\/v2\/posts\/25\/revisions"}],"predecessor-version":[{"id":27,"href":"https:\/\/www.vodasys.net\/index.php?rest_route=\/wp\/v2\/posts\/25\/revisions\/27"}],"wp:attachment":[{"href":"https:\/\/www.vodasys.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vodasys.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vodasys.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}