Share via

Copying a textrange object?

Anonymous
2010-10-05T15:24:40+00:00

Iam writing a macro to take a powerpoint textbox which is in the slide title position and convert it to a slide title placeholder. I want to copy the text and all formatting so the appearance of the slide isn't changed. I thought a quick way would be to copy the textrange object from the textbox to the title:

dim text_range as TextRange

Set text_range = ActivePresentation.Slides(x).Shapes(y).TextFrame.TextRange

Set ActivePresentation.Slides(x).Shapes.Title.TextFrame.TextRange = text_range

This produces a compile error "Invalid use of property" in the last line with ".TextRange" highlighted. Are the two types of textrange incompatible? Is there another way to do it without laboriously copying each formatting parameter individually?

Grateful for advice.

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2010-10-06T14:31:35+00:00

You need to set each line property

 With ActivePresentation.Slides(1).Shapes.Title.Line

    .Visible = line_format.Visible

    .ForeColor = line_format.ForeColor

    .DashStyle = line_format.DashStyle

    '--- other properties here

 End With

If you want to copy all the formating from one shape to the other use:

ActivePresentation.Slides(1).Shapes(3).PickUp

ActivePresentation.Slides(1).Shapes.Title.Apply

Regards,

Shyam Pillai

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Anonymous
2010-10-05T15:45:51+00:00

Hi,

You've got it right, you just need to remove 'Set'.   

dim text_range as TextRange

Set text_range = ActivePresentation.Slides(x).Shapes(y).TextFrame.TextRange

ActivePresentation.Slides(x).Shapes.Title.TextFrame.TextRange = text_range

This should work now. However, this operation will assign the text to the  title placeholder but it will take the formating of the placeholder and not the source text box.

For that to happen use copy/paste (see below) or format the text programatically by reading the formatting information from the source textbox and applying it (See Runs: An example of it is provided here -http://skp.mvps.org/pptxp006.htm

Dim text_range As TextRange

Set text_range = ActivePresentation.Slides(x).Shapes(y).TextFrame.TextRange

text_range.Copy

ActivePresentation.Slides(x).Shapes.Title.TextFrame.TextRange.Paste

Regards,

Shyam Pillai

Was this answer helpful?

0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-10-05T16:34:08+00:00

    That's amazing! What is it actually doing? Is the chr(11) character something that gets added in copy/paste?

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-10-05T16:25:50+00:00

    Try this:

    Set text_range = ActivePresentation.Slides(x).Shapes(y).TextFrame.TextRange

    text_range.Copy

    With ActivePresentation.Slides(x).Shapes.Title.TextFrame.TextRange

        .Paste

        If Asc(.Characters(.Characters.Count)) = 11 Then

            .Characters(.Characters.Count, 1).Delete

        End If

    End With

    Regards,

    Shyam Pillai

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-10-05T16:09:27+00:00

    Thanks for a brilliant answer. The only problem I have is that when you paste the text range you seem to paste a CR/LF at the end of the text. I am trying to remove this in the code but haven't figured it out yet!

    Was this answer helpful?

    0 comments No comments