0
votes

I'm developing macro for a news paper in ms publisher. It seems that "grow textbox to fit text" option is not working on next linked textbox, but I founded a manual trick which is:

  • set focus on first textbox
  • press Ctrl+end button to reach the cursor to end of textbox
  • press Ctrl+Shift+Down arrow key
  • Ctrl+Shift+End to Select nextlinked textbox's remaining text
  • press Ctrl+X to cut it and then break Link of first textbox
  • select second textbox and press Ctrl+v to paste cut text into second textbox
  • then set "grow textbox to fit text" option in formate tab.

It is easy and testable for you in manual steps, but would be amazing if someone could help me to do same steps with vba macro coding.

I repeat steps for macro target:

  • go to end of first textbox's text
  • then select remaining text of story which is in other textbox linked with first
  • then cut selected text
  • then break link
  • then past cut-ed text into second textbox
  • then set "grow textbox to fit text" in format textbox --text autofitting.

I'm successful in linking textboxes in vba which is as:

    ActiveDocument.Pages(1).Shapes(1).TextFrame.NextLinkedTextFrame = ActiveDocument.Pages(1).Shapes(2).TextFrame
 ActiveDocument.Pages(1).Shapes(2).TextFrame.AutoFitText = pbTextAutoFitShrinkOnOverflow

I want to make automatic newspaper macro.

1

1 Answers

0
votes

The solution is as simple as:

    Dim shpTextBox As Shape

Set shpTextBox = ActiveDocument.Pages(1).Shapes.AddTextbox _
 (Orientation:=pbTextOrientationHorizontal, _
 Left:=0, Top:=0, _
 Width:=100, Height:=100)
 ActiveDocument.Pages(1).Shapes(1).TextFrame.TextRange.Text = "A Quick Brown Fox Jumps over the lazy Dog, A Quick Brown Fox Jumps over the lazy Dog, A Quick Brown Fox Jumps over the lazy Dog"




Set shpTextBox = ActiveDocument.Pages(1).Shapes.AddTextbox _
 (Orientation:=pbTextOrientationHorizontal, _
 Left:=500, Top:=500, _
 Width:=500, Height:=300)

ActiveDocument.Pages(1).Shapes(1).TextFrame.NextLinkedTextFrame = ActiveDocument.Pages(1).Shapes(2).TextFrame

ActiveDocument.Pages(1).Shapes(1).TextFrame.TextRange.Select
If Selection.Type = pbSelectionText Then

MsgBox ActiveDocument.Pages(1).Shapes(1).TextFrame.TextRange.Text


End If


ActiveDocument.Pages(1).Shapes(2).TextFrame.TextRange.Select
If Selection.Type = pbSelectionText Then

MsgBox ActiveDocument.Pages(1).Shapes(2).TextFrame.TextRange.Text



ActiveDocument.Selection.TextRange.Cut
'ActiveDocument.Pages(1).Shapes(2).TextFrame.TextRange.Cut

ActiveDocument.Pages(1).Shapes(1).TextFrame.BreakForwardLink



ActiveDocument.Pages(1).Shapes(2).TextFrame.TextRange.Paste
ActiveDocument.Pages(1).Shapes(2).TextFrame.TextRange.Select
ActiveDocument.Pages(1).Shapes(2).Width = 50

ActiveDocument.Pages(1).Shapes(2).TextFrame.AutoFitText = pbTextAutoFitGrowToFit

End If

    ActiveDocument.Pages(1).Shapes(2).TextFrame.AutoFitText = pbTextAutoFitGrowToFit