how restrict view in MS word 2010? - vba

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.

Related

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

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).

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

VBA script to insert anchor position for autoshapes in Microsoft Word 2007

I'm beyond the limits of my kindergarten-level VBA skills so would like to ask if anyone here can help me write a VBA script to help me work stepwise through my Word document and adjust the anchoring position of all the AutoShapes in the document.
I have a 400-page book in Microsoft Word with at least one and sometimes several marginalia (sidenote) on each page in a thin column to the left of the main body text column. These sidenotes are a concise 'pointer' to a particular point made in the body text and need to appear directly to that point's left.
Each sidenote is in its own AutoShape (within a textbox in that shape). The AutoShapes were placed by the author in an inconsistent way. Mostly they are anchored to a position on the page.
However, I need to repaginate. This will cause the body text to flow differently and I need the sidenotes to flow with it (approximately or exactly)!
So before I repaginate I want to make sure I anchor each AutoShape to the paragraph it belongs to and not to the page it is currently on.
I don't know if that can be done automatically, since I don't know how Word could deduce a purely spatial relationship between an AutoShape and a paragraph.
So I'm guessing I have to make do with a "semi-automatic" process. Something like this:
Press a button to start VBA script
Select next AutoShape
Prompt for user to enter cursor in body text where anchor is to be placed
Resume macro
Place anchor for that AutoShape in that position
Change vertical position paramater of AutoShape to "relative to paragraph"
and "0 mm"
(Alternative, not 0 mm but another value deduced to more
accurately position AutoShape)
Change width parameter of AutoShape to
a particular fixed value 37 mm (some of them were a little
inaccurately drawn)
End cycle and go back to beginning to
Select next AutoShape
Hope that is all understandable.
I've tried to record a VBA script to do some of this but have no idea how to build in the user prompt.
Any help much appreciated!
Craig
You may be better off creating a macro that works on one shape at a time, or anchor all the shapes manually (which you're almost doing anyway) and then write a macro to take care of the various parameters and settings you want.
If you really want to prompt the user while the macro is running you'll need to look into modeless dialogs (not possible on the Mac). See this link: http://www.bettersolutions.com/vba/VXV113/SE846743531.htm
Basically, you'd have to create your own dialog and then show it modelessly so that the user could still place the cursor before hitting OK. If you're new to VBA, this could be difficult to set up.
While searching for solutions to this, I found a post on another forum from someone trying to do something very similar. He was developing a set of tools for editors using Word and until I find the ultimate solution I am using his "Shapes" tool which allows me to change parameters on each AutoShape I select at-a-click instead of opening up and closing a dialogue box each time, plus selecting a different tab each time... His tools can be downloaded at his Editors' Toolkit website.

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!

In RealStudio, how can I intercept pasting of rich text?

I'm trying to create a simple text field for WYSIWYG editing. However, I only want to allow certain types of formatting (e.g. Bold, Italic, Underline and a single heading type but no colors or different fonts.)
The issue is if I use an editor that can accept formatting, someone can create or copy formatted text in another program, then simply paste it into the text field and all that formatting goes with it, allowing things I'm not interested in, such as different fonts, colors, etc. I don't want to allow that.
At best, I want to automatically strip out any formatting that I don't support. At worst, I want to simply paste whatever as plain text making them have to reformat it. But in no case do I want to just dump the clipboard to the text area.
Any thoughts on how to do this?
I would recommend creating a new text field/text area class and creating an EditPaste menu handler that (a) does what you're looking for in terms of handling the clipboard's text and (b) returns true to prevent the default pasting from happening. This is safer than using the Key down events because the user might manually select paste from the edit menu.
You can access the text on the clipboard by creating a Clipboard object.
To subclass the textfield and intercept the paste menu command:
With your Project open, go to Project Menu > Add > Class
Select the new class in the project's tab and in the properties panel set the super to TextField
Double-click on the class to edit it
Click the "Add Menu Handler" mid-toolbar button in your class
Change the menu item name to "EditPaste". Put your code in before the "return true" and be sure to leave the return true in there.
Your code can then format and paste the text manually and override the default paste function.
Any command-V or control-V in that text field will cause that menu handler to fire. Any contextual menus would be added by you anyway since real basic does not create the default contextual menus, so you'd have control over that as well.
To add the text field to a window, just change the filter above the objects list to Project controls, and drag the class in from there.
You could intercept the paste yourself by intercepting it in the KeyDown events. Then, you could look to parse it yourself. That could be kind of tricky but I think that's about the only way you could do it.
It might just be easier to parse the resulting StyleRun after the paste and strip out formatting you don't want.
Alternately, you could look at the Formatted Text Control from True North Software and override the paste methods of the control (you get all the source) and just handle it yourself.
Either way, I think it will be a fair amount of work.