How to: create a textbox inside the Word document....?

Posted on 2003-02-27
Medium Priority
Last Modified: 2012-05-04

By using Macros

i.  how can i place a textbox in the current cursor position. b'cause when creating a textbox (using ActiveDocument.Shapes.AddTextbox method), i don't know the exact position of the left, top, width, height parameters in the AddTextbox method and these parameters dynamically varies. so that how can i get the cursor position.

ii. how can i place an image inside the textbox

iii. is there any option to hide/show the textbox in the word document

thnks in advance
Question by:navamnk
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 43

Expert Comment

by:Steve Knight
ID: 8040301
1) Not sure.  I've always worked with predfined text boxes but then used the left, top, etc. paramaters to fix their position within the code.


Selection.InlineShapes.AddPicture FileName:=file$, LinkToFile:=False, SaveWithDocument:=True


ActiveDocument.Shapes(i).Height = 0 (having recorded the height paramater to set it back later if you need...)

You can also use the Zorder property to "hide" multiple images behind each other.



Accepted Solution

MacroWizard earned 90 total points
ID: 8041195
Here, try this code. This will give you a little tiny text box at the cursor position (selection.range), with 0 as the top parameter and 0 as the left parameter. Obviously change these parameters as you see fit.

One tip. Always find out what the name of your shape is (Word automatically gives them names). That way you can maniputlate it any way you want later. Sometimes I rename the shapes beginning with, say "MW", so later on I know which shapes are mine and which the user put in. That way I can work with only my shapes.

Example, pleading lines in a document. I add the lines to the header and name them "PL" plus whatever Word has named them. That way I can easily go in and delete all shapes starting with "PL." See example below.

Dim strname As String

' add shape and get its name
strname = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 0, 20, 20, Selection.Range).Name

' Rename shape
activedocument.Shapes(strName).Name = "PL" + strName

Regarding hiding the shape, I found the visible parameter but have never tried it. This would argue more for you to name your shapes, so you can change the visibility of the shapes.

ActiveDocument.Shapes(strname).Visible = msoFalse

Hope this helps.
LVL 44

Expert Comment

ID: 9283620
This question has been classified as abandoned.  I will make a recommendation to the moderators on its resolution in the next round.  I would appreciate any comments by the experts that would help me in making a recommendation.

It is assumed that any participant not responding to this request is no longer interested in its final deposition.

If the asker does not know how to close the question, the options are here:


EE Cleanup Volunteer

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question