For information about creating event handlers, see How to: Create event handlers in Office projects. In C#, you must add an event handler for the button to the Startup event. Private void insertText_Click(object sender, EventArgs e) Private Sub insertText_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
How to do text boxes for word online code#
In Solution Explorer, right-click ThisDocument, and then select View Code on the shortcut menu.Īdd the following code to the Click event handler of the button. To write to the text box when the button is clicked Populate the text box when the button is clickedĮvery time the user selects the button, Hello World! is added to the text box. Now you can write the code that will run when the button is clicked. On the View menu, select Properties Window.įind TextBox1 in the Properties window drop-down box and change the Name property of the text box to displayText.ĭrag a Button control to the document and change the following properties. You can modify the way controls and shape objects are inserted by changing the default on the Edit tab of the Options dialog box in Word. In Word, controls are dropped in-line with text by default. Verify that the document is open in the Visual Studio designer.įrom the Common Controls tab of the Toolbox, drag a TextBox control to the document.
The user interface controls consist of a button and a text box on the Word document. Visual Studio opens the new Word document in the designer and adds the My Word Button project to Solution Explorer. In the wizard, select Create a new document.įor more information, see How to: Create Office projects in Visual Studio. To create a new projectĬreate a Word Document project with the name My Word Button. The first step is to create a Word Document project. For more information, see Configure a computer to develop Office solutions. You need the following components to complete this walkthrough:Īn edition of Visual Studio that includes the Microsoft Office developer tools. For more information, see Personalize the IDE. The Visual Studio edition that you have and the settings that you use determine these elements. Set oRngAnchor = (1).Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The text is placed at the shape anchor point which usually is at the start of a paragraph. Because textboxes are a subset of shapes they will also be processed. The following macro will step through every shape in the document and if a shape contains a textframe, extract the text and delete the shape. The above macros only process textboxes and not other shapes containing text. It would seem that your "pictures" are rectangles (or perhaps another shape such as a rectangle with rounded corners) containing textframes. However a rectangle to which a textframe has been subsequently added looks and acts the same but is not a textbox. You can then edit the text so that it appears as you want.Ī text box is a shape comprising a rectangle with a textframe and text. When this macro is done, you can do a search for "Textbox start" and you will be at the beginning of text that used to be in the text boxes that are now gone from your document. ' insert the textbox text before the range object ' copy text to string, without last paragraph mark If you prefer to transfer the text from the text boxes to the document, prior to deleting the text box, then a slight modification on the above macro will work: In other words, if a text box is used for placement of text, then the text in that text box is deleted along with the text box itself. You should realize that this macro removes all of the text boxes and their contents.
The following macro will quickly remove all text boxes in your document: If you want to get rid of only the text boxes, then the quickest solution is to use a macro. (I told you this was a brute force method.)
The obvious drawback to this approach is that the other formatting of the original document is also lost, and you must reformat the entire document. The document text, minus the text boxes, is now in the new document.
If you do a lot of work with documents from other people, you may have a need to remove text boxes in those documents.