![]() |
|
#1
|
|||
|
|||
![]()
Is it possible to insert a rich text control control into a particular position in a Word doc template.
I have the following which works fine for a shape, but not the rich text control. Set shp = ActiveDocument.Shapes.AddTextbox( _ Orientation:=msoTextOrientationHorizontal, _ Left:=10, Top:=5, Width:=500, Height:=41) shp.TextFrame.TextRange.Text = "Please add company name" shp.TextFrame.TextRange.Style = oStyle shp.Line.Visible = msoFalse shp.RelativeVerticalPosition = wdRelativeVerticalPositionPage shp.Top = InchesToPoints(1.1) shp.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage shp.Left = InchesToPoints(0.27) Thanks in advance. |
#2
|
||||
|
||||
![]()
A content control is not a shape, which can be independent of the text and thus placed anywhere, but is essentially a text item. it has the same characteristics with regard to placement as text typed from the keyboard.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
||||
|
||||
![]()
And, as such, you could insert it into a textbox or floating table and position it that way.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
![]()
Ok, understood. That's clear. What would you recommend I insert that can be used as a text placeholder into which the user will type "Insert Company Name" but will sit in the header position, not shift onto the next page, but can be picked up as a Style for the table of contents. My shape (as per the code provided) moves onto the next page despite "move with text" not being checked, and "lock anchor being checked". With thanks
|
#5
|
|||
|
|||
![]()
Hi I tried that, but it still jumped onto the same page, even with the layout settings as described.
|
#6
|
|||
|
|||
![]()
I found that if I group the two textboxes, they stay put. I need to do this via VBA, however. What is wrong with this code
Set shp = ActiveDocument.Shapes.AddTextbox( _ Orientation:=msoTextOrientationHorizontal, _ Left:=10, Top:=5, Width:=500, Height:=41) shp.TextFrame.TextRange.Text = "Please add company name" shp.TextFrame.TextRange.Style = oStyle shp.Line.Visible = msoFalse shp.RelativeVerticalPosition = wdRelativeVerticalPositionPage shp.Top = InchesToPoints(1.1) shp.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage shp.Left = InchesToPoints(0.27) shp.Name = Shape1 Selection.GoTo What:=wdGoToPage, Which:=wdseekcurrent ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPage '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Set shp2 = ActiveDocument.Shapes.AddTextbox( _ Orientation:=msoTextOrientationHorizontal, _ Left:=10, Top:=5, Width:=500, Height:=41) shp2.TextFrame.TextRange.Text = "Please add title" shp2.TextFrame.TextRange.Style = bStyle shp2.Line.Visible = msoFalse shp2.RelativeVerticalPosition = wdRelativeVerticalPositionPage shp2.Top = InchesToPoints(1.5) shp2.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage shp2.Left = InchesToPoints(0.27) shp2.Name = Shape2 With Selection.ShapeRange .LockAnchor = True End With ActiveDocument.Shapes.Range(Array("Shape1", "Shape2")).Select Selection.ShapeRange.Group It doesn't group the two. Can anyone assist ![]() |
#7
|
||||
|
||||
![]()
Perhaps you could explain why the particular content needs to be 'in the header position' instead of in the body of the page concerned? From what you've described, it would appear you can achieved the same visual outcome with a small top margin and a 'different first page' layout, with some additional padding content to increase the effective header size on the 2nd & subsequent pages of the Section concerned.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
![]()
That's a good question as it is, in essence, a header. I do have the 'different first page' option. The only reason I don't have my text boxes in the header itself is that I need the input to be picked up in the table of contents. If I place them within the header, they aren't picked up.
|
#9
|
||||
|
||||
![]()
I understand that, but what you haven't explained is why you can't achieve the desired outcome the way I suggested.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#10
|
|||
|
|||
![]()
Ah! I see what you mean. That works. Now I just need to figure out how to add the text into that position via VBA.
|
#11
|
||||
|
||||
![]()
If you insert a content control there, or a bookmark, a table cell, textbox, or any other addressable content, that's very straightforward. Obviously, though the details vary according to what addressable content you choose to use.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#12
|
|||
|
|||
![]()
I'll try a table or bookmark as the text boxes keep jumping to the next page
![]() |
#13
|
||||
|
||||
![]()
For a bookmark, you could use:
Code:
ActiveDocument.Bookmarks("BookmarkName").Range.Text = "My Text" Code:
ActiveDocument.Tables(1).Range.Cells(1).Range.Text = "My Text"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#14
|
|||
|
|||
![]()
The table works perfectly. Thank you very much!
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
nolanthomas32 | Word VBA | 4 | 09-19-2017 06:25 AM |
![]() |
irvingdog | Word | 2 | 01-26-2017 04:18 PM |
![]() |
Testor | Word VBA | 4 | 07-08-2012 07:55 AM |
![]() |
keithacochrane | Word | 1 | 05-28-2012 05:06 PM |
Templates: automatic text generation from Rich Text content control | Chickenmunga | Word | 0 | 10-01-2008 11:16 AM |