Link to home
Start Free TrialLog in
Avatar of aditee
aditee

asked on

How to merge several text boxes into one textbox in PowerPoint using excel vba

Hi,
I have copied some text from excel to PowerPoint. But now, i want to merge all the text boxes in PowerPoint into one but usong excel vba. Please help me out with the solution.
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

Rather than creating individual text boxes and then merging them, why not create one and then add to it with subsequent copied text?
Avatar of aditee
aditee

ASKER

Hi,
Actually, i am copying the text from different cell and thus automatically text box is been created for each cell. Though i had created one text box at starting of the code. But every time it copies the text from the cell while pasting in slide automatically text box is been created.
Add PowerPoint as a Topic for your question and your question will get seen by more experts with ppt knowledge.
Avatar of aditee

ASKER

Hi, i have already added PowerPoint as topic for my question.
If you adopt Rob's suggested methodology you can append text to an existing TextRange in PowerPoint using the InsertAfter method like this:

With Application.ActivePresentation.Slides(1).Shapes(1)
    .TextFrame.TextRange.InsertAfter MyString
End With

Open in new window


Note that this method will not maintain the text formatting so the format used will be that of the last character in the existing text range. If you want to maintain the source text format, you could do something like this:

' Appends the formatted text range from on shape to another
Sub AppendTextRange()
  Dim oTR1 As TextRange2
  Dim oTR2 As TextRange2
  With ActivePresentation.Slides(1)
    Set oTR1 = .Shapes(1).TextFrame2.TextRange
    Set oTR2 = .Shapes(2).TextFrame2.TextRange
    oTR2.Copy
    oTR1.InsertAfter(oTR2).PasteSpecial (msoClipboardFormatNative)
  End With
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jamie Garroch (MVP)
Jamie Garroch (MVP)
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aditee

ASKER

Thanks for your help. The code worked very well.