Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Formatting textbox shape in word from excel

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
brad@printedvisions.com.au - 15 Jul 2007 07:28 GMT
Hi All,

I'm making an application in excel to set up a word document and add a
textbox to it.  However, I'm having trouble setting the line and color
of the textbox.  Does anyone know the specific code to do this as the
following code produces the following error:

Run-time error '438':
Object doesn't support this property or method

Public Const pts2mm = 2.834467

Sub ControlWord()
   Dim wrdApp As Word.Application
   Dim wrdDoc As Word.Document

   Set wrdApp = CreateObject("Word.Application")

   wrdApp.Visible = True

   Set wrdDoc = Documents.Add

   Dim x As Object

   'Add the textbox
   Set x = wrdDoc.Shapes.AddTextbox(msoTextOrientationHorizontal, 40
* pts2mm, 90 * pts2mm, 20 * pts2mm, 6.6 * pts2mm)

   With x
       .Name = "Textbox 1"

       'Add text and set font and size
       With .TextFrame
           .TextRange = "01/07/07"
           .TextRange.Font.Name = "Arial"
           .TextRange.Font.Size = "10"
       End With

       'Select textbox and set background and lines to nothing
       .Select
       With Selection.ShapeRange '<---- error occurs here
           .Line.Visible = msoFalse
           .Fill.Visible = msoFalse
       End With

   End With

   'Clean up
   Set x = Nothing

   Set wrdDoc = Nothing
   Set wrdApp = Nothing
End Sub

I've added the reference to word in the vbe so I don't know why it
doesn't work.  I tried this code first in a module inside word and it
worked fine.

Can anyone assist?
Jay Freedman - 16 Jul 2007 15:00 GMT
Hi Brad,

I don't see how that code could have worked within Word. After the .Select,
the selection consists of the textbox itself, which doesn't contain a
ShapeRange -- that's why the error occurs. The paragraph in which the
textbox is anchored would have a ShapeRange that includes the textbox, but
that's not what you're doing.

If you properly declare the variable x as Word.Shape, then you don't need to
do the .Select at all -- just use the .Line and .Fill properties of the
object x to do the work:

   Dim x As Word.Shape
...

   With x
       .Name = "Textbox 1"

       'Add text and set font and size
       With .TextFrame
           .TextRange = "01/07/07"
           .TextRange.Font.Name = "Arial"
           .TextRange.Font.Size = "10"
       End With

       .Line.Visible = msoFalse
       .Fill.Visible = msoFalse

   End With

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> Hi All,
>
[quoted text clipped - 55 lines]
>
> Can anyone assist?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.