Home |
Search |
Today's Posts |
#1
|
|||
|
|||
macro to enter data and print doc
I need some help to write a "simple" macro that will allow me to enter data
from the keyboard and place it in a document tjen to save the documenet and print it. The overall task is paper based and not suitable (due to lack of funds) to working directly from a laptop. It involves entering a clients name and address in the appropriate places in a form of six pages, then saving the name and address to a file (or appending to a text file) then printing the pages with thename and address entered. I have some very elementry knowledge of vba and I am sure that it is easy using a message box and beginner's vba but I do not know where to start. -- In the hope that asking the question is often the beginning of greater understanding |
#2
|
|||
|
|||
If the only changes you are making to the document are to the name and
address, then pop up the forms menu and insert a form field for the name and another for the address at their first locations in the document and check the calculate on exit check boxes of both fields' properties. At the other locations use REF fields to recall the information you have just entered. Lock the form and save it as a template. No vba required. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org David Gladstone wrote: I need some help to write a "simple" macro that will allow me to enter data from the keyboard and place it in a document tjen to save the documenet and print it. The overall task is paper based and not suitable (due to lack of funds) to working directly from a laptop. It involves entering a clients name and address in the appropriate places in a form of six pages, then saving the name and address to a file (or appending to a text file) then printing the pages with thename and address entered. I have some very elementry knowledge of vba and I am sure that it is easy using a message box and beginner's vba but I do not know where to start. |
#3
|
|||
|
|||
Graham - many thanks for your elegant response. The REF field works well but
I am having porblems getting the "form field" to work although this might be due to my personal lack of understanding. The solution does not generate or update a text file, eg csv that would provide a database or simple list of contacts. Maybe I did notstress the importance of this feature. My own rather fuzzy thoughts involved a MSGBOX, FILLIN or ASK as a front end from where the namefield, addressfield would appear a) in all pages of the form letter (there are 6 pages and the namefield appears 20 times) then prints all pages and b) updates or appends a csv file database. Sorry I did not make this clear "Graham Mayor" wrote: If the only changes you are making to the document are to the name and address, then pop up the forms menu and insert a form field for the name and another for the address at their first locations in the document and check the calculate on exit check boxes of both fields' properties. At the other locations use REF fields to recall the information you have just entered. Lock the form and save it as a template. No vba required. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org David Gladstone wrote: I need some help to write a "simple" macro that will allow me to enter data from the keyboard and place it in a document tjen to save the documenet and print it. The overall task is paper based and not suitable (due to lack of funds) to working directly from a laptop. It involves entering a clients name and address in the appropriate places in a form of six pages, then saving the name and address to a file (or appending to a text file) then printing the pages with thename and address entered. I have some very elementry knowledge of vba and I am sure that it is easy using a message box and beginner's vba but I do not know where to start. |
#4
|
|||
|
|||
The general principle of bookmarks and ref fields will still work, but the
requirement to append the input to a data file converts this from a simple task to a more complicated one. Essentially you would run a macro on exit from the last form field used, to gather the data from the bookmarks and then write it to another document. If you start with a blank document called (say) names.doc and you have two fields called Text1 and Text2 then something along the lines of Dim sName, sAddress, sOutput As String sName = ActiveDocument.Bookmarks("Text1").Range sAddress = ActiveDocument.Bookmarks("Text2").Range sOutput = sName & ", " & sAddress & vbCr Documents.Open FileName:="Names.doc" Selection.EndKey Unit:=wdStory Selection.InsertAfter sOutput would add your field content to the names.doc file. It needs work to produce a useable function, but it should set you on your way - there are plenty of vba enthusiasts active in the Word vba groups if you need further help with this. A more elegant alternative would be to create a userform to gather the data, but the principle is the same. There is lots of information on userforms on the MVP web site (link in sig. block) to get you started with this. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org David Gladstone wrote: Graham - many thanks for your elegant response. The REF field works well but I am having problems getting the "form field" to work although this might be due to my personal lack of understanding. The solution does not generate or update a text file, eg csv that would provide a database or simple list of contacts. Maybe I did notstress the importance of this feature. My own rather fuzzy thoughts involved a MSGBOX, FILLIN or ASK as a front end from where the namefield, addressfield would appear a) in all pages of the form letter (there are 6 pages and the namefield appears 20 times) then prints all pages and b) updates or appends a csv file database. Sorry I did not make this clear "Graham Mayor" wrote: If the only changes you are making to the document are to the name and address, then pop up the forms menu and insert a form field for the name and another for the address at their first locations in the document and check the calculate on exit check boxes of both fields' properties. At the other locations use REF fields to recall the information you have just entered. Lock the form and save it as a template. No vba required. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org David Gladstone wrote: I need some help to write a "simple" macro that will allow me to enter data from the keyboard and place it in a document tjen to save the documenet and print it. The overall task is paper based and not suitable (due to lack of funds) to working directly from a laptop. It involves entering a clients name and address in the appropriate places in a form of six pages, then saving the name and address to a file (or appending to a text file) then printing the pages with thename and address entered. I have some very elementry knowledge of vba and I am sure that it is easy using a message box and beginner's vba but I do not know where to start. |
#5
|
|||
|
|||
Thanks
"Graham Mayor" wrote: The general principle of bookmarks and ref fields will still work, but the requirement to append the input to a data file converts this from a simple task to a more complicated one. Essentially you would run a macro on exit from the last form field used, to gather the data from the bookmarks and then write it to another document. If you start with a blank document called (say) names.doc and you have two fields called Text1 and Text2 then something along the lines of Dim sName, sAddress, sOutput As String sName = ActiveDocument.Bookmarks("Text1").Range sAddress = ActiveDocument.Bookmarks("Text2").Range sOutput = sName & ", " & sAddress & vbCr Documents.Open FileName:="Names.doc" Selection.EndKey Unit:=wdStory Selection.InsertAfter sOutput would add your field content to the names.doc file. It needs work to produce a useable function, but it should set you on your way - there are plenty of vba enthusiasts active in the Word vba groups if you need further help with this. A more elegant alternative would be to create a userform to gather the data, but the principle is the same. There is lots of information on userforms on the MVP web site (link in sig. block) to get you started with this. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org David Gladstone wrote: Graham - many thanks for your elegant response. The REF field works well but I am having problems getting the "form field" to work although this might be due to my personal lack of understanding. The solution does not generate or update a text file, eg csv that would provide a database or simple list of contacts. Maybe I did notstress the importance of this feature. My own rather fuzzy thoughts involved a MSGBOX, FILLIN or ASK as a front end from where the namefield, addressfield would appear a) in all pages of the form letter (there are 6 pages and the namefield appears 20 times) then prints all pages and b) updates or appends a csv file database. Sorry I did not make this clear "Graham Mayor" wrote: If the only changes you are making to the document are to the name and address, then pop up the forms menu and insert a form field for the name and another for the address at their first locations in the document and check the calculate on exit check boxes of both fields' properties. At the other locations use REF fields to recall the information you have just entered. Lock the form and save it as a template. No vba required. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org David Gladstone wrote: I need some help to write a "simple" macro that will allow me to enter data from the keyboard and place it in a document tjen to save the documenet and print it. The overall task is paper based and not suitable (due to lack of funds) to working directly from a laptop. It involves entering a clients name and address in the appropriate places in a form of six pages, then saving the name and address to a file (or appending to a text file) then printing the pages with thename and address entered. I have some very elementry knowledge of vba and I am sure that it is easy using a message box and beginner's vba but I do not know where to start. |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I print a mail merge data source without the main document | Mailmerge | |||
How to print blank merge data as a blank line? | Mailmerge | |||
How do I update Word 2002 to create merged faxes? | Mailmerge | |||
Merge Error - Contains Too Few Data Field | Mailmerge | |||
How to print addresses on envelopes from Outlook Contacts data ? | Mailmerge |