PDA

View Full Version : Solved: Trying to create a text box in word from excel



tropix100
05-17-2012, 02:12 AM
Hey guys. Not sure if this is an excel or word query.
I have code which is creating 2 images of cell data onto a word doc.
In between these 2 images I want to insert a text box which is editable from work. But it must be created from excel.

Sheets("WordPrep").Range("B1:G5").Copy
Sheets(Page).Select
Application.ScreenUpdating = True
objWord.Selection.PasteSpecial , DataType:=4
objWord.ActiveDocument.Content.ParagraphFormat.Alignment = 1
Application.ScreenUpdating = False
' Here is where I want the textbox created and placed
Sheets("WordPrep").Range("B6:G35").Copy
Sheets(Page).Select
Application.ScreenUpdating = True
objWord.Selection.PasteSpecial , DataType:=4
objWord.ActiveDocument.Content.ParagraphFormat.Alignment = 1
Application.ScreenUpdating = False
objWord is a word object rather than using references for compatibility reasons. This gives me 2 images on a Word doc.

Really need help on this one.

Thanks

Bob Phillips
05-17-2012, 03:12 AM
Sheets("WordPrep").Range("B1:G5").Copy
Application.ScreenUpdating = True
objWord.Selection.PasteSpecial , DataType:=4
objWord.ActiveDocument.Content.ParagraphFormat.Alignment = 1
Application.ScreenUpdating = False

objWord.Selection.TypeParagraph
objWord.Selection.TypeParagraph

Sheets("WordPrep").Range("B6:G35").Copy
Application.ScreenUpdating = True
objWord.Selection.PasteSpecial , DataType:=4
objWord.ActiveDocument.Content.ParagraphFormat.Alignment = 1

objWord.Selection.MoveUp Unit:=5, Count:=1
objWord.Selection.Range.ContentControls.Add (0)

Application.ScreenUpdating = False
Application.CutCopyMode = False

tropix100
05-17-2012, 04:07 AM
Thanks for your reply xld.

What you provided is good for me but its not what I need fo this project.
I need a textbox inserted where you put "objWord.Selection.TypeParagraph".

If its not possible then I can use your suggestion

Bob Phillips
05-17-2012, 04:25 AM
You mean one line higher?

tropix100
05-17-2012, 05:09 AM
No....
I mean I want to place a TEXTBOX control and then size it differently for each time the doc is created .

Bob Phillips
05-17-2012, 05:27 AM
I am not understanding you.

snb
05-17-2012, 06:21 AM
Sub snb()
Sheets("WordPrep").Range("B1:G5").Copy

With createobject("Word.document")
.Shapes.AddTextbox(msoTextOrientationHorizontal, 20, 40, 120, 60).TextFrame.TextRange.Paste
_ _ _ _ _ _
end with
End Sub

tropix100
05-18-2012, 12:34 AM
snb > You got it. After a little tweeking it is what I want. Thankyou