From: Graham Mayor on 7 Mar 2010 02:01 Doug has answered the first part of your question. Word 2007 is less strict about folder location and you can make any folder a trusted location so it does not automatically save templates in 'the templates folder'. When you save a document as a template, if you want it in a particular location you must select that location before saving from the dialog. To facilitate this you can add your preferred templates location to the places bar at the left of the dialog. -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> "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, >
From: Graham Mayor on 7 Mar 2010 02:04 The lines Set oDoc = Documents.Open(FileName:="C:\Documents and Settings\Administrator\My Documents\A Consult Letter.doc") are in fact one line. The news editor has broken the line into two. You must rejoin them. However you would be better with the template approach. It is not good practice to re-use documents and sooner or later it usually leads to data loss. -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> "Mark" <Mark(a)discussions.microsoft.com> wrote in message news:D9229F26-95E4-4EA8-A06D-C62CF5E35059(a)microsoft.com... > 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. > >'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 8 Mar 2010 22:17 I tried adding the code but I must be adding it to the wrong places as I keep getting run time errors like "Object variable or With block variable not set". Mark "Graham Mayor" wrote: > Add the following macro to the userform to populate the list box. > > Private Sub UserForm_Initialize() > With Me.ListBox1 > .AddItem "Hispanic-American" > .AddItem "White" > .AddItem "African-American" > .AddItem "Asian" > End With > End Sub > > You could populate the list from an array eg > > aRace = Array("Hispanic-American", "white", "African-American", "Asian") > With Me.ListBox1 > For i = 0 To UBound(aRace) > .AddItem aRace(i) > Next i > End With > > but unless you are deriving a variable length array from elsewhere it is not > worth doing so here > > include in the Private Sub CommandButton1_Click() > the line > oVars("varRace").Value = Me.ListBox1.Value > To add the selected value to the variable. > > or if you are following Greg's example > add to UpdateLetterFields(frmCL As ConsultLetter) > the line > oVars("varRace").Value = frmCL.ListBox1.Value > > > -- > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > Graham Mayor - Word MVP > > My web site www.gmayor.com > Word MVP web site http://word.mvps.org
From: Doug Robbins - Word MVP on 8 Mar 2010 23:19 Right click on the Form in the Project Explorer and select View Code. It is in the code window that then opens that you should have the Initialize statement that Graham suggested. -- 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:20F99E9E-2B95-49E0-B0BB-D4167365C1E9(a)microsoft.com... > I tried adding the code but I must be adding it to the wrong places as I > keep > getting run time errors like "Object variable or With block variable not > set". > > Mark > > > > "Graham Mayor" wrote: > >> Add the following macro to the userform to populate the list box. >> >> Private Sub UserForm_Initialize() >> With Me.ListBox1 >> .AddItem "Hispanic-American" >> .AddItem "White" >> .AddItem "African-American" >> .AddItem "Asian" >> End With >> End Sub >> >> You could populate the list from an array eg >> >> aRace = Array("Hispanic-American", "white", "African-American", "Asian") >> With Me.ListBox1 >> For i = 0 To UBound(aRace) >> .AddItem aRace(i) >> Next i >> End With >> >> but unless you are deriving a variable length array from elsewhere it is >> not >> worth doing so here >> >> include in the Private Sub CommandButton1_Click() >> the line >> oVars("varRace").Value = Me.ListBox1.Value >> To add the selected value to the variable. >> >> or if you are following Greg's example >> add to UpdateLetterFields(frmCL As ConsultLetter) >> the line >> oVars("varRace").Value = frmCL.ListBox1.Value >> >> >> -- >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<> >> Graham Mayor - Word MVP >> >> My web site www.gmayor.com >> Word MVP web site http://word.mvps.org
From: Mark on 9 Mar 2010 01:06 Doug, I guess I am lost as here is what I tried as code in the userform area and they did not work: 1) Option Explicit Private Sub ListBox1_Click() End Sub Private Sub CommandButton1_Click() Dim oVars As Variables Set oVars = ActiveDocument.Variables oVars("varDoctor1").Value = Me.TextBox1.Value oVars("varDoctor2").Value = Me.TextBox2.Value oVars("varStreetAddress").Value = Me.TextBox3.Value oVars("varCityStateZip").Value = Me.TextBox4.Value oVars("varPatient").Value = Me.TextBox5.Value oVars("varAge").Value = Me.TextBox6.Value oVars("varRace").Value = Me.ListBox1.Value Private Sub UserForm_Initialize() ActiveDocument.Fields.Update Unload Me End Sub Private Sub UserForm_Click() End Sub 2) Option Explicit Private Sub ListBox1_Click() End Sub Private Sub CommandButton1_Click() Dim oVars As Variables Set oVars = ActiveDocument.Variables oVars("varDoctor1").Value = Me.TextBox1.Value oVars("varDoctor2").Value = Me.TextBox2.Value oVars("varStreetAddress").Value = Me.TextBox3.Value oVars("varCityStateZip").Value = Me.TextBox4.Value oVars("varPatient").Value = Me.TextBox5.Value oVars("varAge").Value = Me.TextBox6.Value oVars("varRace").Value = Me.ListBox1.Value With Me.ListBox1 ..AddItem "Hispanic-American" ..AddItem "White" ..AddItem "African-American" .AddItem "Asian" End With End Sub Private Sub UserForm_Initialize() ActiveDocument.Fields.Update Unload Me End Sub Private Sub UserForm_Click() End Sub Mark "Doug Robbins - Word MVP" wrote: > Right click on the Form in the Project Explorer and select View Code. It is > in the code window that then opens that you should have the Initialize > statement that Graham suggested. > > -- > 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
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: Bringing different windows to the front Next: Direct edit of Building Blocks |