473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Adding text to a Shape using Microsoft.Office.Interop.Word

I am trying to add text to a shape but I can't figure out how to do it.. I am using the method

Expand|Select|Wrap|Line Numbers
  1. public void DrawOnDoc(object oMissing, Microsoft.Office.Interop.Word._Document oDoc)
  2.         {
  3.             oDoc.Shapes.AddShape(1, (xPos / 2) + 100, (yPos / 2) + 100, nWidth / 2, nHeight / 2, oMissing);
  4.         }
to add a shape to a document, but I can't find anything about adding text to the shape. Is it possible to do this?
Apr 27 '11 #1
5 11555
GaryTexmo
1,501 Expert 1GB
I would recommend using MsoAutoShapeType for the type instead of just the number, it makes your code a bit easier to read :D

As for adding text to it... I'm not sure. I notice that the AddShape method returns a Shape object, but I don't see any text in there. Hmm...

You might be able to get it from the document itself. This article seems to suggest you can..

http://www.eggheadcafe.com/community...using-vba.aspx

I tried to make a quick program to test but I can't seem to find the reference to Microsoft.Office.Interop.Word (or whatever it is), it's not in my list. I wonder if it's because I have the Express edition of VS...
Apr 27 '11 #2
I have that too. I had to add it manually as a reference. Microsoft.Office.Core and Microsoft.Office.Interop.Word are what I have. It's under the COM tab of Add References. Microsoft Office 14.0 Object Library, or something like that.
Apr 27 '11 #3
GaryTexmo
1,501 Expert 1GB
There we go.

And I knew it had to be in there somewhere...

Expand|Select|Wrap|Line Numbers
  1. Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
  2. Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
  3.  
  4. oWord.Visible = true;
  5. oWordDoc = oWord.Documents.Add();
  6.  
  7. Microsoft.Office.Interop.Word.Shape s = oWordDoc.Shapes.AddShape((int)Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 0, 0, 100, 100);
  8. s.TextFrame.TextRange.Text = "Blah";
Apr 27 '11 #4
Thank you again. Remind me to put you in my will.
Apr 28 '11 #5
GaryTexmo
1,501 Expert 1GB
I like cookies... ;)

It was tough to find information on that... two people looking is better than one, I just happened to figure it out before you this time, but I'm pretty sure you'd have gotten there.
Apr 28 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: bracoute | last post by:
Hello.... can you plz help me ... i'm using vbscript in asp.net and i've referenced the microsoft.office.interop.word.dll so that i can use the wordApplication object to automate MS Word.. the...
1
by: R Reyes | last post by:
ISSUE (reposted) =========================== Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? For many people, they say they add the...
1
by: Alan T | last post by:
VS 2005 and MS Office 2003 installed. I can include Microsoft.Office.Core and Word in the references so I can add the using Microsoft.Office.Interop.Word. However, my workmate cannot do the...
9
by: sajithkahawatta | last post by:
my web page C#.net is work properly in my iis .but when i publish in another server it give errers.i used vs2005 and ms word 2003. but in the server there is no vs2005 or word installed. it has only...
0
by: chovatia.jaydeep | last post by:
Hi, I want to hide Menubar/Toolbar in Word/Excel 2007. I followed steps given in the link: http://msdn2.microsoft.com/en-us/library/aa338202.aspx Following above linke, i created Add-In...
0
by: kalyanilovesme | last post by:
how to import that name space(Microsoft.Office.Interop.Word) in asp.net with c#.. i added the reference of microsoft.office11.0.object library even though this name space not coming...
1
by: mac73 | last post by:
Hi, I am using asp.net 2.0 application with Microsoft.Office.Interop.Word version 11.0.0.0 on windows server 2003 with IIS 6.0. It works fine with access given to Network service. The scenario...
0
by: frederick.the.fool | last post by:
I'm writing a project that does Visio automation. I'm writing it in C+ +/CLI because it needs to reference a good amount of native C++ code. One way to call the Visio API, of course, is to use...
1
by: PulkitZery | last post by:
Hello! I am looking to find Microsoft.Office.Interop.Word dll for Office 2007, to include it into my project’s bin folder. I tried to download it from : ...
0
by: jojee | last post by:
Hi All i have a little problem in my project that is i m using word document for reading the contents from it so i did add the references Microsoft.Word.Object library and in the wen.config file i...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.