Which text field should I use in word and how to fill it - vba

I am trying to use a text field in my word template document but I confused which one should I use?!!
which one you recommend?
Rick text
Text
Text Form Field
My second question is how to address these component in Macro? I use below code:
ActiveDocument.FormFields("TextboxName")
Third question is how to set a value to this component in Macro? so many website use .Value but I don't know why I cannot find this field in above component.
Last question is: if I use any form field, a gray shadow exist below my component, how I can remove it? it is even coming in check print.:(
I am using word 2007.

You would add : textFormField.
you would pass value by Me.FormFields("Text1").Result = "abc"
in your controls tab,
somewhere next to the formField control find the "formFieldShadding"
control. when you select that control your gray shadding will
disappear.

Related

Insert/replace string in existing text form field in Word (VBA)

So I'm trying to create a conditional dropdown in Word. I've used a Legacy Drop-Down Form Field with multiple options.
What I want to happen is when one of the options is selected from the dropdown (and then I guess you have to Tab to enter it...), the Legacy Text Form Field below, that has a simple default text, should populate with a new string from the case statement.
Things that I've already done/got working:
the drop down is working, and on exit it runs a macro
case statement is written out
the result of the case statement is in a variable (string type), let's call it StringVar
can pull the text form field's text (default text) with ActiveDocument.FormFields("TextBox").Result
What I figure out, however, is how to replace the default text in the already existing Text Form Field with the case statement's string variable text.
I've tried
ActiveDocument.FormFields("TextBox").Result = StringVar
but it doesn't change anything inside the text form field. The default text is still there.
So I can answer my own question after pondering and being hit with an "oh, duh" moment.
I had unprotected the document (ActiveDocument.Unprotect Password:="") in order to do this:
ActiveDocument.Content.InsertAfter Text:=("This is my text")
because I was wondering if I was grabbing the right string.
Turns out,
ActiveDocument.FormFields("TextBox").Result = StringVar
DOES work. BUT the file has to be protected (filling in forms) for it to replace the string in the text form field. Otherwise, nothing shows up even though the result had indeed been updated. Fancy that.

Difference between Combobox properties SelText and Text?

I don't quite understand the differences between the combobox properties SelText and Text.
If I want to send the content of a combobox as a parameter to another procedure, should I send .text or .selText?
If I want to make enter text into a combobox using a macro, should I write the text in .selText or .Text?
The difference is really given in the name (SelText vs. Text) where Sel stands for Selected. One is used to return or modify the selected text (i.e. SelText) and the other is used to return or modify the entire text (i.e. Text).
If no text is selected in the ComboBox then they return and modify the same value.
I suspect you want to use Text unless you are specifically interested in the selected text.
This appears to be consistent for an ActiveX control on a Worksheet or for a control on a User Form.

MS Word 2010 template text form field condition

we got a word template that gets a mail feed from SQL.
It has three text form field :
txtFirstname
txtLastname
txtcompany
If the feed has no firstname and lastname i.e blank and has a company name then
the company name needs to be moved to the txtFirstname field. hence moved to the left. Aligned to the left.
Text form field control is in Developer\legacy forms\text from field
I guess need code to run macro on exit in the txtcompany field...
When they are blank they should just have a space inside the container, so they should automaticaly move to the left if the others are blank. Are there any styling applied to them? Also make sure they are not in a table, as it wont move.
Hope this helped - Jim

Word: remove page from multipage userform

I want, depending of the previous choice from the user just let some tab's being seen.
Once i am new in VBA, i start showing all the tab's and after the choice from the user, i remove the tab's that i don't want. For that i am using this line of code
MultiPage1.Pages.Remove "name of the tab"
The problem is, if i don't have the same CAPTION and the NAME field of the tab the tab is not remove.
If anyone have a diferent solution for this or another away to remove without have to change the caption for the same name of NAME field i would be thankful.
Thanks
You can give a page of a multi-page control a different name from the caption in the Properties Window. You can access it from the View menu.
I've highlighed the name of the control in yellow and the caption in aqua.
If the captions are unique, you could use a Select Case statement to get the name, based on the caption. Are users actually typing in the caption of the tabs they want, or selecting from check boxes? In either case, the captions would have to be unique, so you could do something like:
Select Case True
Case Check1.Value
MultiPage1.Pages.Remove Pages("kp").Index
Case Check2.Value
MultiPage1.Pages.Remove Pages("jp").Index
End Select
That's a bit rough, but is that the general idea?

Storing a hidden, non-editable variable in a form. Word 97 Compatible

I need a non-editable field in a word form that can be read in vba.
Currently I use a text field, which is hidden. As in:
ActiveDocument.FormFields("DocID").Select
Selection.Font.Hidden = false
//do read then re-hide it.
However users can still 'tab' in to this text field and overwrite the document ID that is there and thus invalidate the vba macro. And unfortunately that is what happens.
I can set the text field property 'Fill-in enabled' to false which gives the desired effect in the form, i.e the user cannot edit it. However now this text field cannot be read in vba.
ActiveDocument.FormFields("DocID").SomeProperty
//throws error 'The requested member of the collection does not exist'
So my question is, is there a way I can store a hidden variable in a word form that can be read in a vba macro?
Unfortunately this has to be a Word-97 compatible solution.
You could use custom document properties instead, see here:
http://msdn.microsoft.com/en-us/library/aa537154(v=office.11).aspx