B
brad
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?
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?