Change color of selected form-fields with VBA in MS Word - vba

Is there any way to globally change the selection color of all form-fields in MS Word? I have a test form that I fill out as I'm doing a test. My eyes go back and forth between the meters I read and the form I fill out. I then tab to the next field to fill out and read another meter. The default colors of the form-fields between when the field is selected for input and when it is not is not very different. I find myself trying to find my place again when looking at the form again.
Is there any way to globally change the color of all form-fields so that the color when it is selected is much different than the color when not selected? Thanks.
Keep in mind that the form is protected so that only changes to the fields are allowed. So I will have to unprotect the document before I can change it and then reprotect it after I'm done. This much I can do. I can change colors when I enter and exit a field. But this slows down how fast I can fill out the form. So I was hoping there was a property I could set to change only the selection color and cycle through all fields when the document is first opened. Any suggestions out there?

Sorry, the only options for form fields are grey or uncolored. To switch between those 2, VBA is not required. Instead, choose Developer>Legacy Forms and click the 5th icon from the left Form Field Shading (looks like an a with hatch marks around it).

Related

Word document text boxes "remember" what was in them previously

I am using a VBA userform to randomly generate values to be sent into a Word document to provide random questions on various math topics (for my students).
This seems to work well except that when I exit the userform (me.hide) and the values are sent and focus is back in the document, the previous values are still briefly visible every time I move the mouse.
This only happens for an instant. The correctly sent values appear if there is no mouse (or window slider) activity taking place. If I view another application and do some activity there and then return to the Word document the display is fine as well.
The flipping of values is visually annoying. Has anyone out there encountered a similar issue?
To reproduce:
Create a Word document with an ActiveX Textbox and button. The button activates a userform which also contains a Textbox and a button to send the Textbox value back to the Textbox in the document.
In my case, when the button in the document is clicked the form opens and the value does get returned to the Word document, but when rolling the mouse or moving the slider at the edge of the window the previous value in the text box briefly flickers into view. Here is the code from the document button:
Private Sub cmdOk_Click()
ThisDocument.TextBox1.Value = TextBox1.Value
Me.Hide
End Sub
I am using Word 2016 and Windows 10.
I tried to use the "new" Word textboxes but I do not know how to communicate with them from a userform. It is so simple using the "old" text boxes.
ActiveX controls were designed for VBA UserForms. It's possible to insert them on the surface of a Word document or Excel spreadsheet, but they don't always behave optimally. Content controls (and the legacy form fields), on the other hand are designed for the surface of a Word document.
In order to write to a content control you can use code like this:
ActiveDocument.SelectContentControlsByTitle("name").Item(1).Range.Text
Closer to what you're trying to do with identifying the content controls could be:
ActiveDocument.SelectContentControlsByTitle(TextBox1.Name).Item(1).Range.Text = TextBox1.Value
Why it's so complicated: The team that designed content controls wanted to avoid the problems people ran into with bookmarks and form fields, that a name could not be duplicated in a document. It's possible to give the same name to multiple content controls. So it's not possible to identify a content control using Document.ContentControls("name").
Instead, Document.SelectContentControlByTitle needs to be used, which returns an array of content controls. If there's only one (or if you want only one), then you can add on .Item([index]) to get the single content control directly.
Rather than type in a static name, you can query the UserForm's textbox control for its name, if that makes things easier for you.

How can i remove the border between 2 textboxes that are next to each other in order to look as one

Say I have this form of a timer:
https://gyazo.com/ffdae5829005768d53fcb625c6b971b8
The minute textbox and the second/millisecond textbox are next to eachother but there is an obvious line in between them which is the border between both seperate textbox. How do I remove this border to make it look like its just 1 seemless textbox?
While viewing the form in designer mode you can right click one of the textboxes and select Properties. This should open a pane that will permit you to change the BorderStyle property to None. Do this for both textboxes and it will appear seamless.
You can do what NoAlias did but this will not show any border at all. I think you want to make it look like a single textbox right?
I have three other suggestions:
Use a single textbox to show Minute and Second/Millisecond.
Use a label. Set it's background color to the same as textbox background and put it between those textboxes. This will make it look
like it's a single box too.
Do what NoAlias did, and add a RectangleShape around the two textboxes to make it look like a textbox. You can find it in the toolbox under the heading Visual Basic PowerPacks.

How can I select (or copy) text from a Word 2010 ActiveX label?

A Word 2010 document has an ActiveX label that displays some text. Is there any way to make the text selectable, or otherwise copy-able, from a user's point of view, so he can paste it somewhere else?
Use case: I give the form to someone, they fill it out and return it to me. The element in question is a Label which, when double clicked, produces UserForm1 which has a ListBox on it. Once one or more selections are made and the user presses OK on UserForm1, the Label in the Word doc gets updated. I then receive the form back, and want to right click the label, copy the text, and paste it into an email.
You can't, at least from an end-user's point of view. Let me explain.
I started out wanting to achieve this with a Label, but soon found I couldn't copy the text that was displayed there using conventional ctrl-c or right-click > copy.
So, I switched it up to a TextBox. This worked somewhat, and the data was displayed, though with one flaw: Word 2010 seems to put a bunch of unselectable space between the last line in the TextBox and the bottom of the TextBox, making most the contents hidden until you scrolled back up to the top of it.
Here's what it looked like:
Notice all the empty, unselectable space below the last item in the list?
The solution to my problem of 100% of the text not being displayed in the box was to use this line of code, which places the cursor at the top of the text after the values are placed in the TextBox:
ThisDocument.functionalComponentsTextBox.SelStart = 0
This basically simulates the user manually clicking in the TextBox and pressing the Up key until he reaches the top of the TextBox. With that, the selections from the ListBox are now stored in the TextBox, the contents of which can be copied and pasted wherever as part of our business processes.
Here's what it looks like after: a perfect match when compared to the properly-displayed Label approach! Added bonus: the text is selectable, and the TextBox is customizable so I removed the border from it... can't tell the difference!

how restrict view in MS word 2010?

I have a word file containing many paragraph. I have a heading for each paragraph.Also listed all heading in a single page. What i want is, When user click on heading it can view only that paragraph only. he will not able to view other paragraph. To view other paragraph user need to comeback to the page where all headings are listed.
The way I would try to handle it is to put each paragraph into its own Continuous section and set all of the text as hidden. On the page where you have your headings, put a checkbox next to each one and in the checkbox properties, you can assign it to run a macro (remember to do this after you write your macros).
Now you just write a number of simple macros (one for each paragraph you have) that will change the font property of that paragraph by turning the hidden setting off, while changing the font properties of every other paragraph by turning the hidden settings on.
Now for your checkboxes, you'll need to set them up so that if one is selected, the rest of them are unselected. (You may be able to simply use a radio button instead of a checkbox, but I can't remember off the top of my head if radio buttons allow you to run a macro when selected.)
The thing you need to keep in mind is that some people may have their Word settings set up to always show hidden text, which would ruin the point of keeping stuff hidden. However, I believe you may get around that by adding another macro that turns that setting off as soon as the document is opened.

Reset Excel to default borders

Ok, so you know what a spreadsheet looks like when you open a new on in Excel; the borders are a light blue. These are only on the screen though, if you print the sheet it will not have borders. Say you've applied some various formatting to the sheet (background color, etc.) and those "default" borders are gone. My question is how to you get them back? Simply doing a Clear Formats will not always work.
Specifically I am talking about Excel 2007 but I believe all versions do this.
Any ideas?
Thanks,
Ryan
I had this issue, grid lines appeared to be missing on some cells.
Took me awhile to figure out that the color of those cells were white.
I clicked format cell, pattern and then selected "no color" (instead of white)
The the grid lines were visible again.
I hope this helps others as it took me a while to figure out why.
If you have applied border and/or fill on a cell, you need to clear both to go back to the default borders.
You may apply 'None' as the border option and expect the default borders to show, but it will not when the cell fill is white. It's not immediately obvious that it has a white fill, as unfilled cells are also white.
In this case, apply a 'No Fill' on the cells, and you will get the default borders back.
That's it. No messy format painting, no 'Clear Formats', none of those destructive methods. Easy, quick and painless.
Just go to Home> Cell Style > Normal
khir
If you're trying to do this from within Excel (rather than programmatically), follow these steps:
From the "Orb" menu on the ribbon, click the "Excel Options" button near the bottom of the menu.
In the list of choices at the left, select "Advanced".
Scroll down until you see the heading "Display options for this worksheet".
Select the checkbox labeled "Show guidelines".
My best answer for this is to simply use format painter. This might be a bit of a pain, but it works rather well as the problem you are facing is that Gridlines are covered by fill and other effects that are layered on top. Imagine putting a piece of white paper on top of your grid, the grid lines are present underneath, but they just don't show.
So try:
Clicking on a cell in the spreadsheet with the format that you want
Under the ribons, go to Home and format painter, it should be a smaller icon near the paste button.
Now highlight any cell that you want to apply this format to and it will set the font, color, background etc. to the same as the cell selected. The value will be preserved.
From my experience this is the easiest way to do this quickly. Especially when pasting things in and out of excel.
Again this is not the programmatic way of solving this problem.
Another way, There is check box Page Layout tab with Gridlines [ ] View which should be checked.
you just need to change the line color and you can apply it without problem
I was having the same trouble with importing from Excel 2010 to Access, appending an "identical" table. Early on in the wizard it said not all my column names were valid, even though I checked them. It turns out that it saw an "empty" column with no column name. When I tried using the import wizard to create a new table instead, it worked. However, I noticed that it had added a blank column to the right of my data and called it "Field30". So I went back to the spreadsheet I was trying to import, selected the columns to the right of the data that I wanted, right-clicked and chose "clear contents." That did the trick and I was able to import the spreadsheet, appending it to my table.
In Excel 2016 for Mac, I clicked the Excel menu, then clicked Preferencesā€¦
I then clicked the View icon.
whereupon I found a Gridlines Checkbox next to a Color Picker.
Regardless of whether the Gridlines checkbox os checked or not, if you change the color in the Color Picker dropdown menu, your cell borders will become that color. (I believe the change took place after i quit excel and opened the document the next day to continue working on it but I can't accurately remember.)
Changing the color picker back to Automatic will return your cell borders to the default (black) color on-the-fly.
N.B. Because I'm a newbie I cannot insert the screen shots I prepared ahead of time. šŸ˜ 
I understand this is an old post. But it is programmable. Otherwise make sure your fill is set to "No Fill" and your boarders are set to "No Boarder" via the user interface shown in the previous posts.
Sub clear()
Range("A4:G1000").Borders.LineStyle = xlNone
Range("A4:G1000").Interior.ColorIndex = xlNone
End Sub()
Select the cells that you need to affect the style and go to Home then click cell style and select Normal as show in the below snapshot