Word 2010 ActiveX control forms - formatting issues - vba

Hopefully a quick one
I am creating a form in Word with a Save macro that uses an ActiveX Label as a button. The label works fine as a button but I am having 2 issues:
when using the document in normal mode, the coding text in curly brackets for the label is still visible - see image
How do I get rid of this?
When printing the form, the button pushes the header text down a line:
You can see in the first picture that there is no gap here.
Thanks for your help.

(1) Press Alt+F9 to toggle off display of field codes (and make sure you're not in Design Mode).
(2) is impossible to be sure without having the document in front of me but...
Printing problems are notorious with ActiveX controls, which were designed for use with UserForms, not for the document surface. Your best bet for stability would be to use a one-row, two-column table with the button on the left and the address on the right.
Or use a MacroButton field code instead of an ActiveX control.

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.

VB.net Application wide Copy and paste (Text)

Im trying to implement application wide copy and paste short cuts. (ctrl+C) etc.
The application consists of forms drawn in tab pages, and there are quite alot of forms. Ideally im after something (in the keypress of the main form) that would just see if the active control is a text box and If so pastes or copies text. Doing so on every text box on every form is unfeasible.
Another approach i guess would be to override the text box control application wide?
There must be an easy way to do this surely.
My googling so far hasn't come up with anything. Thankyou.
Ok; turns out there was a simple problem preventing this from working.
The EDIT menu in the menu bar on the main parent form was 'consuming' these keyboard short cuts.
Deleting this menu fixed the issue instantly.

Tab between Excel worksheet cells and form controls

I have a worksheet in Excel 2010 that is protected and used as a form for user-fillable values. The form contains 80 cells to be filled in and two radio button form controls to be selected. The form consists of two pages on the worksheet that are placed side by side horizontally (horizontally is a better user experience than vertically in this situation).
To get tabbing to go through the cells on the first page and then on the second page in the desired order, I used the solution on page 4 of the thread at "http://answers.microsoft.com/en-us/office/forum/office_2007-excel/establishing-enter-order-on-a-protected-sheet/e7a223f3-2dae-4c7b-a37f-1819c68be5dc". This works excellently for regular cells.
The problem is how can I also tab to the radio buttons, which are located about a third of the way through the desired tab sequence? Unfortunately, it's not as easy as just adding the radio button names to the TabOrder array mentioned in the thread.
I've found various threads talking about tabbing between controls, but nothing that solves tabbing from regular cells to form controls, between the form controls, and then back to regular cells.
I'm relatively new to Excel VBA programming and could really use your help. :-)
Thanks!
Don
I can't add a comment, so I have to put this in the answer section even though it is not really an answer: Not sure if this is still an issue for you, but are you using Option Buttons or a Group Box. And are you using Form Controls or ActiveX.
The only thing that I have found that may help is to tab to the group itself, then use the arrow keys: "When you tab to the group, you can use the arrow keys to select the next/previous option." and "2. You can set an accelerator key on each one by adding an ampersand (&) before one letter in the label. For example, if the label's caption is "&Next", it will appear as "Next", and Alt-N will be the keystroke that selects that option. Be careful not to choose a keystroke that opens a menu -- for example, don't pick F, because Alt-F almost alway opens the File menu."
From: http://www.mrexcel.com/forum/microsoft-access/557082-how-idiotic-no-way-tab-stop-option-button-within-group.html

Word Macro to add predefined content at the end of document on click of button

I have an document in word, which has some fields to be filled, and an button to which I want to assign a macro. When that button is clicked, that same form with empty fields needs to be appended to the end of document, including the button (which can be clicked again and do the same thing).
Here is the document I have:
https://drive.google.com/file/d/0B_2kyqxMx5x4UkxfOHJhOGVPdnc/view?usp=sharing
The main problem with what you want to do is dynamically linking the button to the macro code to be executed. The most obvious type of button to use is the legacy ActiveX control in the Ribbon's Developer tab. But that requires its own procedure entry in the document's ThisDocument class module. While it's possible to add code to modules "on the fly" this involves disabling a security option.
A more straignt forward approach is to use the MacroButton field. This creates a clickable text within the document. It can display text or a graphic (so that it looks like a button) and is assigned the name of any public Sub that takes no parameters:
{ MACROBUTTON NameOfMacro Click here }
Ctrl+F9 to insert the field code brackets; Alt+F9 to toggle between field code and field result.
Graphics in Word 2010 and later:* The was a change to the graphics engine in Word 2010 which affects the behavior of graphics objects in the MacroButton field. Clicking the object triggers the Ribbon utility for working with graphics - the field code no longer "hides" the graphic. There are a number of ways you can work around this:
Use an IncludePicture field (which works with the old graphics format) to bring in an outside picture file. Once the linked picture is in the field it can be converted to a static picture by selecting the IncludePicture field and pressing Ctrl+Shift+F9. Word respects the old graphic format and the picture is click-able.
{ MacroButton NameOfMacro {IncludePicture "C:\\Path\\picture.jpg" } }
Use the old *.doc file format. Note that this will restrict some of the things that can be done with the document, but it will force use of the old graphics engine.
Instead of a MacroButton field, use the WindowBeforeDoubleClick event or WindowSelectionChange event to run the code.
*With the exception of unlinking the IncludePicture field (which I discovered myself), this information came from this discussion on the Microsoft Answers site
If you want to run the macro with a single rather than a double-click (the default) you need to run the following line of code. This applies to the entire Word application and needs to be run everytime Word restarts. You could put it in an AutoNew macro in the template / AutoOpen macro in the document:
Application.Options.ButtonFieldClicks = 1
The simplest way to store the entire content you want to insert repeatedly is as a Building Block (formerly known as AutoText).
BuildingBlocks are stored in templates. If your document is being created from a template, that would be the logical place. Another possibility would be a special template you use for this purpose. Normal.dotm can also be used but keep in mind this does sometimes get removed.
(Note: if you're using a template for the document that would also be the best place to store the macro attached to the macro button.)
Once this is set up, all your code needs to do is insert the BuidlingBlock at the end of the document.

ReportViewer: two text colors, one cell

Is it possible to have 2 areas of text in one cell such that each can have a different color? You can do this in crystal reports but I cannot see a way to do this in ReportViewer. What it is doing is essentially highlighting an important text fragment if it appears in a cell description to draw the users attention. I am fairly new to reportviewer so it for now I am assuming it's my lack of knowledge that is making this difficult. I am using VS2010.
Thanks.
Turns out VicarlnATutu wasn't quite right.
You can do this, but only if you are using VS2010 (which I am) because it includes the new SSRS rendering engine for SQL-Server 2008. This allows you to put some basic HTML into a field and have multiple formats in one cell. For more info see below:
http://msdn.microsoft.com/en-us/library/cc645967.aspx
http://msdn.microsoft.com/en-us/library/cc627491.aspx
One thing that tripped me up is what they call a 'placeholder' in the MS documentation is the little bit of text inside the textbox control that shows up by default. You can select two different things on the control in VS2010. One is the textbox itself. Right clicking on the textbox gives you 'text box properties'. The other thing you can select is the default text INSIDE the textbox. Right clicking on this 'placeholder' text gives you a different context menu where you can select 'placeholder properties'. This is where you can change the cell to accept HTML.
No, unfortunately not. I don't know if there are custom controls out there for ReportViewer, but the built-in TextBox only supports setting color (be it Foreground or Background) for the entire thing.
ah, good to know. kind of a unintuitive way to tell a TextBox to display HTML, but nice to know that you can!