What I mean is, for example I have a text:
Hello, I am using stackoverflow
And when I click on the word "Hello", it becomes bold, but other text does not change:
Hello, I am using stackoverflow
You may be interested in the following Word Application events:
WindowBeforeDoubleClick is fired when the editing area of a document window is double-clicked, before the default double-click action. The current selection is passed as a parameter.
Public WithEvents appWord as Word.Application
Private Sub appWord_WindowBeforeDoubleClick _
(ByVal Sel As Selection, Cancel As Boolean)
Dim intResponse As Integer
intResponse = MsgBox("Selection = " & Sel & vbLf & vbLf _
& "Continue with operation on this selection?", _
vbYesNo)
If intResponse = vbNo Then Cancel = True
End Sub
WindowBeforeRightClick is fired when the editing area of a document window is right-clicked, before the default right-click action.
Public WithEvents appWord as Word.Application
Private Sub appWord_WindowBeforeRightClick _
(ByVal Sel As Selection, Cancel As Boolean)
Dim intResponse As Integer
intResponse = MsgBox("Selection = " & Sel & vbLf & vbLf _
& "Continue with operation on this selection?", _
vbYesNo)
If intResponse = vbNo Then Cancel = True
End Sub
Yes, it is possible in Word to apply any character formatting, such as bold, to any word by clicking it, if you use the Format Painter as follows:
Select a word that already has the formatting that you are after (e.g.
select a word that is bold).
Double-click the Format Painter button on the toolbar/ribbon. This "copies" the formatting of the selected word into memory.
Click in the middle of the word which you want to format (e.g. make bold). This "pastes" the formatting you copied in the previous step. The word you click will become formatted with the same character formatting as the word you selected in Step 1 (e.g. the whole word will become bold with a single click).
OPTIONAL. Scroll using the mouse and the scroll bars to find additional words and click them to format them as well. You can also select text with the mouse (click and drag) to make it bold.
To stop format painting, click the Format Painter button again, one time. Using arrow keys to navigate, or Esc, or other keys to type text may also stop the Format Painter. The Format Painter button on the Ribbon changes appearance to show when it is depressed (Format Painter active) or not (Format Painter inactive).
Note: if you single-click the Format Painter button at Step 2, it will let you "paint" the formatting one time only.
Note: if you selected an entire paragraph in Step 1 before clicking the Format Painter, you can subsequently apply paragraph formatting to the paragraph(s) you click as well as character formatting to the word(s) you click (or click and drag over one or more entire paragraphs to apply both paragraph and character formatting.
The Format Painter is a great tool for applying formatting throughout your document. If you get the hang of the Format Painter, the next step is to learn how to apply, modify and create styles, which are named sets of character and paragraph formatting settings. The pros rely on styles to ensure consistent formatting and to format Tables of Contents and other complex fields.
Related
I am developing an OpenOffice Writer template that can be used to fill in reports for a child-care centre.
There are some standard outcomes, comprising long sentences, and I want the user to be able to select the appropriate sentence from a combo box. I have entered the sentences into a table in Openoffice Base database, which is then connected to a series of combo boxes in a Writer template. However, when the user choose an option that contains a very long sentence, only the text up to the length of the combo box is visible.
What I want to do is have the selected value of the combo-box wrap over several lines when selected so that all the (very long) text appears in the selected box when the user chooses a long sentence from the combo.
I have been looking through the properties of the combo box control, but have yet to identify one that will allow the selected value in the combo box to word-wrap (so that I could make the combo-box several lines in height such that the entire sentence would fit into the box).
Any pointers on how I could do this would be much appreciated.
thanks,
David.
Thanks Jim K, that was helpful. In the end, what I wound up doing was creating a textbox which I named "selectedOutcomeATextBox" immediately below my combo box which was named "OutcomeCombo".
I then attached the following macro code to the textModified event associated with the "selectedOutcomeATextBox":
Sub UpdateOutcomeA
Dim Doc As Object
Dim Form As Object
Dim Ctl As Object
Dim newCtl as Object
Doc = ThisComponent
Form = Doc.DrawPage.Forms.GetByIndex(0)
Ctl = Form.getByName("OutcomeCombo")
newCtl = Form.getByName("selectedOutcomeATextBox")
newCtl.Text = Ctl.Text
End Sub
I also set the "Printable" property of the "OutcomeCombo" to "No", so that when the document prints, the combo box itself does not appear on the printed page, but the "selectedOutcomeATextBox" textbox which has had its value set by the macro when I choose a value from the combo box does appear with the desired text. I also set the "TextType" property of the selectedOutcomeATextBox" text box to "Multi-Line", so that extra long text will wrap to the next line, thereby showing the very long strings that are stored there.
Thanks heaps Jim K.
cheers,
David Buddrige
Apparently combo boxes do not have the MultiLine attribute. The question was asked a few years ago here but was not solved.
One alternative that requires some macro programming is to use a single multi-line text field and then make a scroll bar button that changes the choice. Instead of a scroll bar, two buttons could be used to change the choice (Previous / Next), or even a list box control. Using a list box control in this way would have the advantage that they could see all the choices at once, like a combo box.
Another approach is to break up each sentence and display the parts across several lines of a list box. Then when one line is clicked, all the lines of a sentence are selected at once, using an event listener for the list box. This could be shown in addition to an ordinary editable multi-line text box, in case none of the answers in the list are wanted.
One more idea: Radio buttons can have multiple lines, so dynamically show radio buttons, one for each sentence. A dialog window could be displayed to hold the radio buttons. The result of the dialog would be used to fill the multi-line text field.
Or you could just live with the truncated sentences. Maybe it would help to make the control a little wider, or abbreviate the sentences.
I have created a table of contents (TOC) to my Microsoft Office Word 2013 document using different types of headings linked to the TOC. When I try to modify my TOC 1 style so that only the text inside that TOC paragraph would be bolded, it makes the whole paragraph bolded. What I want to achieve is this:
ONLY THE TEXT HERE IS BOLDED................................1
rather than bolding the dot leader lines nor the page number like this
THE WHOLE PARAGRAPH IS BOLDED.........................1
I can do this manually, but everytime I update my TOC, all these changes go away (everything is bolded/not bolded again). How can I bold only only the text (not dot leaders or page number) inside TOC-style?
Fields throw away edits when updated - there's little you can do to change this. There is a * MergeFormat switch that can be added to field codes in order to retain formatting. The major drawback, however, is that it "remembers" formatting by character location. So if the text changes (gets shorter or longer) the formatting "goes crazy". Therefore, I don't think that will help you.
So all you can really do is re-apply the formatting after each TOC update. The fastest way to do that is using code (a macro, for example).
Here's a macro that works in a quick test on my system. It searches for each TAB character in the TableOfContents. Then, based on the additional information from the OP that only the second tab should be recognized, uses a second range to check whether the position AFTER the tab is within one centimeter of the right margin.
If that's the case, it repositions the find-target Range from that point back towards the beginning of the paragraph, then applies the formatting.
Note 1: You can change the "cushion" used to determine the distance to the right margin by changing the formula assigned to PageNumLimit.
Note 2: I defined a STYLE named Toc1_Text and use that, rather than formatting with BOLD directly. Doesn't really matter, but it feels "cleaner" to me than direct formatting :-)
Sub FormatTextInTOC()
Dim rngFind As word.Range, rngFound As word.Range
Dim bFound As Boolean
Dim toc As word.TableOfContents
Dim infoH As Double, pageNumLimit As Double
Set toc = ActiveDocument.TablesOfContents(1)
toc.Update
Set rngFind = toc.Range
pageNumLimit = rngFind.Sections(1).PageSetup.RightMargin _
- CentimetersToPoints(1)
With rngFind.Find
.ClearFormatting
.Text = vbTab
.Style = word.WdBuiltinStyle.wdStyleTOC1
Do
bFound = .Execute
If bFound Then
Set rngFound = rngFind.Duplicate
'rngFound.Select
rngFound.Collapse wdCollapseEnd
infoH = rngFound.Information(_
wdHorizontalPositionRelativeToTextBoundary)
If infoH >= pageNumLimit Then
'rngFind.Select
rngFind.Collapse wdCollapseStart
rngFind.MoveStart wdParagraph, -1
rngFind.Style = "Toc1_Text"
rngFind.Start = rngFind.Paragraphs(1).Range.End
'rngFind.Select
End If
End If
Loop While bFound
End With
End Sub
When I make a change of style (Font or Paragraph) for a selection of text (example: change the font or text orientation of the selected line), Microsoft Word 2013 apply this change for the whole document in an illogical way.
To fix this issue I need to press 'redo (Ctrl-z)' and word 2013 apply the new style to the text I selected only (it's okay now) but I need to do it every time!
This process has become stressful for me and for my computer CPU especially if I edit a large document because Word 2013 change the style for the whole document.
I never had this problem with Word 2010 or 2007.
If you are applying style from "Style" group of "Home" ribbon, then application of these styles are based on "Style type:" e.g:
1) Paragraph
2) Character
3) Linked (Paragraph and Character)
4) Table
5) List
So, it depends which type of style you are applying and by default it apply on complete target.
The easiest way to save working of CPU and eliminating the stress, is to apply format using "Font" group of "Home" ribbon and if you rapidly use same formatting on different part of document then you can use Ctrl + Shift + C and Ctrl + Shift + V command to copy only formatting of one text to another.
I have two Excel picture objects linked to different forms, each with a text box and OK/Cancel buttons. In one form, the text cursor is in the textbox when clicking the object which is what I want:
but in another it selects the OK command button rather than have the text cursor in the textbox:
I've gone through the form and textbox/command button properties and see nothing about selection, and the 'correct' macro properties appear to be the same as the 'incorrect' one.
What do I do to change the form such that when it's opened the text cursor goes to the textbox instead of the command button being selected?
Quite easy solution is to change TabIndex Property to 0.
So, 1) go to VBA Editor, 2) select your TextBox in your UserForm and 3) change TabIndex Property in Property window as presented below.
Add an event to the form so that when it is initialized it selects the correct texbox.
Private Sub UserForm_Initialize()
TextBox2.SetFocus
End Sub
Before the form is displayed, you can do soemthing like:
TextBox1.SetFocus
Obviously, replace "TextBox1" with whatever the name of your textbox object is.
This should go in whatever event or macro causes the form to .Show, immediately before the .Show statement.
I have an mdb file made by ms access. It got a form inside and inside the form there are one large textbox.
The intention of making this textbox is to show the progress of some work by adding messages inside the textbox:
txtStatus.value = txtStatus.value & "Doing something..." & vbCrLf
txtStatus.value = txtStatus.value & "Done." & vbCrLf
But the problem is, when the height of the text > height of the textbox, the new message is not displayed automatically. The textbox has a scroll bar, but I have to scroll it manually. I would like to auto scroll to the bottom whenever new text pop up.
I tried to add this code(copied from internet) in the On Change property, but the code failed, it does nothing:
Private Sub txtStatus_Change()
txtStatus.SelStart = Len(txt) - 1
End Sub
I wish there would be some simple and beautiful way to achieve this. I don't want to add some code which only work on some computers due to its dependence on the windows platform's kernel/etc.
You can do it via a call to a sub;
AppendText "Bla de bla bla."
.
.
sub AppendText(strText As String)
with txtStatus
.setfocus '//required
.value = .value & strText & vbNewLine
.selstart = len(.Value)
end with
end sub
There is a workaround to the design flaw mentioned by steve lewy in his comment on the original post. It is possible to have a text box that appears to do both of the following:
When the contents are too large for the box, and the box does not
have the focus, the box displays the last part of its contents,
rather than the first part of it.
When the box has the focus, it can scroll to any part of the text,
but it initially shows only the last part of the text, with the
cursor at the end of the text.
This is accomplished by actually having two identically-sized, overlaid text boxes, where one is visible only when the focus is elsewhere, while the other is visible only when it has the focus.
Here’s an example of how to do it in Access 2010.
Create a new Access database, and create a memo field named LongNote in its only table. Fill LongNote with some examples of long text. Create a form for editing that table.
Create a text box called BackBox with the desired size and font, too small to completely show a typical value of its data source, LongNote. (Instead of creating this box, you can rename the default text box created on the form.)
Make an exact copy of that box called FrontBox. Set the data source of FrontBox to be either the entire contents of BackBox or the last part of the contents, as shown below. The size of the last part, measured in characters, depends on the size of the box and its font, as well as on the kind of text to be displayed. It needs to be chosen by trial and error to reliably allow that many characters to be displayed in the box. For instance, here’s the formula for a box that can reasonably hold only 250 characters:
=iif(Len([BackBox])>=250,"... " & Right([BackBox],246),[BackBox])
If the whole value is too large to be shown, three dots precede the part that is shown to indicate that it’s incomplete.
Create another text box called OtherBox, just to have somewhere you can click besides the two boxes already mentioned, so neither of them has the focus. Also create a tiny (0.0097 x 0.0097) text box called FocusTrap, which is used to avoid selecting the entire contents of whatever text box gets the focus when the form is displayed (because text selected that way is hard to read).
Enter the following event-handling VBA code:
' Prevent all text boxes from being focused when a new record becomes
' current, because the focus will select the whole text and make it ugly
Private Sub Form_Current()
FocusTrap.SetFocus
End Sub
Private Sub Form_Open(Cancel As Integer)
FocusTrap.SetFocus
End Sub
' When FrontBox receives focus, switch the focus to BackBox,
' which can display the entire text
Private Sub FrontBox_GotFocus()
BackBox.SetFocus
FrontBox.Visible = False
End Sub
' When BackBox receives the focus, set the selection to
' the end of the text
Private Sub BackBox_GotFocus()
BackBox.SelStart = Len([LongNote])
BackBox.SelLength = 0
End Sub
' When BackBox loses focus, re-display FrontBox – if the text in
' BackBox has changed, then FrontBox will follow the change
Private Sub BackBox_LostFocus()
FrontBox.Visible = True
End Sub
Test the form. When you click on FrontBox, it should disappear, letting you work on BackBox. When you click in OtherBox to remove the focus from BackBox, FrontBox should reappear. Any edits made in BackBox should be reflected in FrontBox.
Back in design mode, move FrontBox so it exactly covers BackBox, and click Position | Bring to Front to ensure that it covers BackBox. Now test the form again. It should appear that a single text box switches between display-the-last-few-lines mode and edit-the-entire-contents mode.
Simply put the following code after linefeed or on Change event txtStatus
txtStatus.SelStart = Len(txtStatus) - 1