From: Mark on 6 Mar 2010 15:08 Graham, Thanks for the help as I really would like to learn how to do this properly. I did reference the correct file to open as I could see the proper file open up in word as I ran the macro. I did all the steps that you instructed but I guess I am not sure what you mean by "create a new document from the template" which should pop up my userform. I opened the new .dotm file but nothing happens. I am not sure what exactly I should do here. Mark "Graham Mayor" wrote: > The macro and form would normally go in the document template, but for your > own use it could work from the normal template. However your reply gives the > clue to the problem You say you have used the macro to open the document and > it seems likely that the wrong document is now being addressed by the > userform and so nothing appears to happen. > > Open your document. Save the document as a template (DOT or DOTM - NOT DOTX) > with the docvariable fields in place. Move the macro and the userform to the > new template - see http://www.gmayor.com/installing_macro.htm > > Rename Greg's macro AutoNew thus > > Sub AutoNew() > Dim oFrm As UserForm1 'or whatever name you gave to your form > Set oFrm = New UserForm1 > oFrm.Show > Unload oFrm > Set oFrm = Nothing > End Sub > > Remove any reference you may have added to opening the document. > > Now create a new document from the template. The form will pop up, you can > fill it and it will update the focvariable fields in the document (provided > they are in the body of the document - if they are elsewhere you will need a > better targeted update macro. > > -- > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > Graham Mayor - Word MVP > > My web site www.gmayor.com > Word MVP web site http://word.mvps.org > <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
From: Doug Robbins - Word MVP on 6 Mar 2010 16:38 Instead of opening the template, you should use File>New and select the template as the basis for the document that you want to create. When you do that, the autonew macro will run. It will NOT run if you use File>Open. -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP, originally posted via msnews.microsoft.com "Mark" <Mark(a)discussions.microsoft.com> wrote in message news:FDE8EEB4-9356-4350-91E8-69E9783466B2(a)microsoft.com... > Graham, > > Thanks for the help as I really would like to learn how to do this > properly. > > I did reference the correct file to open as I could see the proper file > open > up in word as I ran the macro. > > I did all the steps that you instructed but I guess I am not sure what you > mean by "create a new document from the template" which should pop up my > userform. I opened the new .dotm file but nothing happens. I am not sure > what > exactly I should do here. > > Mark > > "Graham Mayor" wrote: > >> The macro and form would normally go in the document template, but for >> your >> own use it could work from the normal template. However your reply gives >> the >> clue to the problem You say you have used the macro to open the document >> and >> it seems likely that the wrong document is now being addressed by the >> userform and so nothing appears to happen. >> >> Open your document. Save the document as a template (DOT or DOTM - NOT >> DOTX) >> with the docvariable fields in place. Move the macro and the userform to >> the >> new template - see http://www.gmayor.com/installing_macro.htm >> >> Rename Greg's macro AutoNew thus >> >> Sub AutoNew() >> Dim oFrm As UserForm1 'or whatever name you gave to your form >> Set oFrm = New UserForm1 >> oFrm.Show >> Unload oFrm >> Set oFrm = Nothing >> End Sub >> >> Remove any reference you may have added to opening the document. >> >> Now create a new document from the template. The form will pop up, you >> can >> fill it and it will update the focvariable fields in the document >> (provided >> they are in the body of the document - if they are elsewhere you will >> need a >> better targeted update macro. >> >> -- >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<> >> Graham Mayor - Word MVP >> >> My web site www.gmayor.com >> Word MVP web site http://word.mvps.org >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<> >
From: Greg Maxey on 6 Mar 2010 18:15 Did you declare the variable oDoc? Dim oDoc as Word.Document. Mark wrote: > Greg, > > I tried your code but I get a compile error that "variable not > defined" at the second line where I have the correct path for my > document. > > Set oDoc = Documents.Open(FileName:="C:\Documents and > Settings\Administrator\My Documents\A Consult Letter.doc") 'Use your > own path of course. > > I am not sure what is wrong as that is the correct path to open the > document. > > Mark > > "Greg Maxey" wrote: > >> Mark, >> >> First, I agree with Graham that you should create a template and not >> recycle an existing document. However, if you want to continue that >> course you could use code something like this: >> >> In a standard module: >> >> Option Explicit >> Dim oDoc As Word.Document >> >> Sub CallUF() >> Dim oFrm As ConsultLetter >> Set oDoc = Documents.Open(FileName:="C:\Consult Letter") 'Use your >> own path of course. >> Set oFrm = New ConsultLetter >> oFrm.Show >> Unload oFrm >> Set oFrm = Nothing >> Set oDoc = Nothing >> End Sub >> >> Sub UpdateLetterFields(frmCL As ConsultLetter) >> Dim oVars As Variables >> Set oVars = oDoc.Variables >> oVars("varDoctor1").Value = frmCL.TextBox1.Value >> oVars("varDoctor2").Value = frmCL.TextBox2.Value >> oVars("varStreetAddress").Value = frmCL.TextBox3.Value >> oVars("varCityStateZip").Value = frmCL.TextBox4.Value >> oVars("varPatient").Value = frmCL.TextBox5.Value >> oVars("varAge").Value = frmCL.TextBox6.Value >> oVars("varRaceSex").Value = frmCL.TextBox7.Value >> oDoc.Fields.Update >> End Sub >> >> In the UserForm module CommandButton_Click use: >> >> Private Sub CommandButton1_Click() >> Me.Hide >> UpdateLetterFields Me >> End Sub >> >> Since you are just learning, you should learn to minimize UserForm >> code as much as possible to only the code required to manage the >> form itself. Here you are passing the form as an argument to a >> called procedure in the standard module. The called procedure does >> the work of updating the document fields with the form data.
From: Mark on 6 Mar 2010 19:54 That did work. Part of the problem may have been that I did not know that I had to click the mouse to get the data into the data fields. I just get hitting the enter button and nothing would happen until I clicked the left mouse button by accident. I also had to cut and paste my .dotm file into the Template folder. Is there a way to do that automatically? Mark "Doug Robbins - Word MVP" wrote: > Instead of opening the template, you should use File>New and select the > template as the basis for the document that you want to create. > > When you do that, the autonew macro will run. It will NOT run if you use > File>Open. > > -- > Hope this helps. > > Please reply to the newsgroup unless you wish to avail yourself of my > services on a paid consulting basis. > > Doug Robbins - Word MVP, originally posted via msnews.microsoft.com > > "Mark" <Mark(a)discussions.microsoft.com> wrote in message > news:FDE8EEB4-9356-4350-91E8-69E9783466B2(a)microsoft.com... > > Graham,
From: Doug Robbins - Word MVP on 6 Mar 2010 20:18 You can use the tab key to move from one control to the next. You may want to set the tab order of the controls so that when you tab, the focus is moved from control to control in an orderly fashion. To set the tab order, click on the View menu and then select Tab Order. -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP, originally posted via msnews.microsoft.com "Mark" <Mark(a)discussions.microsoft.com> wrote in message news:3B96CAB5-D12D-481E-B980-664118FF2E39(a)microsoft.com... > That did work. Part of the problem may have been that I did not know that > I > had to click the mouse to get the data into the data fields. I just get > hitting the enter button and nothing would happen until I clicked the left > mouse button by accident. > > I also had to cut and paste my .dotm file into the Template folder. Is > there > a way to do that automatically? > > Mark > > "Doug Robbins - Word MVP" wrote: > >> Instead of opening the template, you should use File>New and select the >> template as the basis for the document that you want to create. >> >> When you do that, the autonew macro will run. It will NOT run if you use >> File>Open. >> >> -- >> Hope this helps. >> >> Please reply to the newsgroup unless you wish to avail yourself of my >> services on a paid consulting basis. >> >> Doug Robbins - Word MVP, originally posted via msnews.microsoft.com >> >> "Mark" <Mark(a)discussions.microsoft.com> wrote in message >> news:FDE8EEB4-9356-4350-91E8-69E9783466B2(a)microsoft.com... >> > Graham, >
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: Bringing different windows to the front Next: Direct edit of Building Blocks |