Results 1 to 13 of 13
  1. #1
    Bronze Lounger IanWilson's Avatar
    Join Date
    Dec 2000
    Location
    Bristol, United Kingdom
    Posts
    1,523
    Thanks
    0
    Thanked 1 Time in 1 Post

    Recording a macro for paste unformatted (2000)

    I often want to paste in text from say a Word document or some other application and I don't want it to bring its formatting with it, so I use Paste Special - unformatted text. In Word, I use this quite a lot too, so I recorded all the actions for Paste Special - Unformatted text as a macro, created a toolbar button for it and everything is lovely. I thought I would like to do the same in PowerPoint, so I went through the same process - start the macro recorder, go through the few mouse clicks etc. required and stop the recorder again. Trouble is, it dosn't seem to record anything. Nothing happens when I run the macro, and if I edit it to see what's the problem, I find it has created no code. Am I missing something here? Why shouldn't it do the same as in Word. (I'm already sure that's a foolish question! When were these Office applciations ever consistent?)

    Ian

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Recording a macro for paste unformatted (2000)

    Ian,

    You're right - there is no code and, given MS's track record, it is a foolish question to ask for consistency.

    There are certain things that just don't seem to be implemented in an application's object model. This holds for Word also but, I guess, paste special is not one of them (ie, Paste Special does work in Word). I do recall finding other things in Word (word 97 at the time) which generated no code although I don't recall them right now (maybe something having to do with Custom Properties). So ppt doesn't implement paste special. Maybe try adopting Word's code to ppt - but I wouldn't hold out much hope. Or doing the paste special unformatted into Word first and then copying/pasting that to ppt.

    Not that this helps but at least it proves you haven't lost your sanity except if you think MS should be consistent across its apps. That would be a real sign of someone needing help. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Fred

  3. #3
    Bronze Lounger IanWilson's Avatar
    Join Date
    Dec 2000
    Location
    Bristol, United Kingdom
    Posts
    1,523
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Recording a macro for paste unformatted (2000)

    ... so if I knew what I was doing (which I don't) I could write, rather than record, a macro for it?

    Ian

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Recording a macro for paste unformatted (2000)

    Ian,

    if you recorded macros in Word, it sounds like you may know what you're doing and you may be part of the way there. That's why I suggested trying to adopt Word's code for paste special.

    However, I just trying doing this in a quick experiment. Seems like the Word text does not carry over to Word. However, a few observations from the quick test:
    1. In Word, you have a style. You may apply direct formatting to part of the material. If you then copy the material with the direct formatting and paste special unformatted, you just get the material w/o the direct formatting but still with the style applied (I think this is the equivalent of hitting Ctrl+Spacebar to remove direct formatting).
    2. PPT, of course, has no styles for text. So not sure what "unformatted" would be. Your macro could copy and paste the text and then it could apply whatever attributes of bold (none), underline (none), italics (none), embossed (none), etc. you want to represent "unformatted". The only attributes that you might want to consider changing would be font size and style. But in ppt, as in Word, the characters have some size and style. So if the copied text, for example, is Arial 32 point, your macro might consider Times New Roman 24 point to be the equivalent of "unformatted".

    Fred

  5. #5
    Bronze Lounger IanWilson's Avatar
    Join Date
    Dec 2000
    Location
    Bristol, United Kingdom
    Posts
    1,523
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Recording a macro for paste unformatted (2000)

    Well the kind of thing I mean is that I might have some text in Word that is in say 12 point Times New Roman, whether because that is the style or because of direct formatting, and I want to use those words on a PPT slide which will be 32 point Arial. If I just copy and paste it tends to put 12 point TNR on the slide but if I use paste special - unformatted text, it adopts the font, colour etc. already on the PPT slide and comes out as 32 point Arial. Or the source of the text might be something different, like a quotation found on a website or something. Although there is no style as such in PPT, the particular level of text you are at is defined on the slide master.

    Ian

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Recording a macro for paste unformatted (2000)

    There is no PasteSpecial method in PowerPoint VBA. MS has a bassackwards way to emulate it using the Word object model:

    PPT2000: Paste Special Not Available in PowerPoint Object Model

    <UL>Summary
    The Paste Special command is not available within the Microsoft PowerPoint object model. To emulate a Paste Special command, use an object model, such as the Microsoft Word object model, that supports the Paste Special command. This article provides a sample Microsoft Visual Basic for Applications macro (Sub procedure) that uses the Microsoft Word object model to emulate the Paste Special command in PowerPoint.[/list]I haven't tried it. As long as you are going to monkey with VBA and the clipboard, it makes more sense to add a reference to the MS Forms 2.0 Object Library (e.g., by inserting a UserForm) and read the text out as a string using a DataObject. More or less like this:

    <pre>Sub PastePlain()
    'Requires a Reference to the Microsoft Forms 2.0 Object Library
    If ActiveWindow.Selection.Type <> ppSelectionText Then
    MsgBox "Click in the textbox where you want to paste, then try again."
    Exit Sub
    End If
    'Fetch clipboard into a DataObject and retrieve the text
    Dim clip As New MSForms.DataObject, strClip As String
    clip.GetFromClipboard
    On Error Resume Next
    strClip = clip.GetText(1)
    If Err.Number <> 0 Then
    On Error GoTo 0
    If MsgBox("Can't access the ""text"" on the clipboard. Try to paste normally?", _
    vbQuestion + vbYesNo) = vbYes Then
    ActiveWindow.Selection.TextRange.Paste 'Usually nothing seems to happen...
    End If
    Else
    'Insert the text into the textbox
    On Error GoTo 0
    With ActiveWindow.Selection.TextRange
    If .Text <> vbNullString Then 'text is selected
    If MsgBox("Replace selected text?", vbQuestion + vbYesNo) _
    = vbYes Then
    .Text = strClip
    Else
    .InsertAfter strClip
    End If
    Else 'just an insertion point
    .InsertAfter strClip
    End If
    End With
    End If
    Set clip = Nothing
    End Sub</pre>

    My other thought as to how to do this was to paste it and then immediately force it to conform to the placeholder style set in the Slide Master. However, I'm not sure how to do that, either. Ctrl+spacebar will remove manual formatting, but bullets/numbering may remain, as well as other odd bits. But I don't know the corresponding VBA to Ctrl+spacebar. <sigh>

  7. #7
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Recording a macro for paste unformatted (2000)

    Ian,

    If what you're trying to do is bring in some text at a point that matches the "surrounding" text that you're pasting it into, then maybe a macro could be written for that but that is a little beyond my ppt VBA capabilities at the moment. Maybe Jefferson's approach would help.

    However, I did find a few things in playing around that might be of some benefit. In ppt 2000, there are a few properties that might help out. There is a TextStyleLevel object which is part of a collection of TextStyleLevels. Each object corresponds to a bullet level in the Master Slide. The example in the Help shows how to set this in the Master Slide. Not sure if this is particularly useful.

    If you knew the level of where you were pasting to or could find the important attributes of the level (eg, font style, size, etc) or the attributes of the character prior to the insertion point (pasting after the insertion point), you would then want to apply those attributes to the pasted text. Jefferson's example shows the pasting. I think, from what I've seen of other examples, that you would have to know the starting point of the paste and the length of it. Knowing that, you could use statements like

    ActiveWindow.Selection.ShapeRange.TextFrame.TextRa nge.Characters(Start:=6, Length:=4).Select
    ActiveWindow.Selection.TextRange.Font.Bold = msoTrue

    to set attributes of the pasted text to those of the surrounding text. The 1st statement above would select 4 characters starting at position 6 in a text frame (characters seem to be numbered consecutively in a text frame across all bullets - if bullet 1 has 10 characters, the first character of bullet 2 is 11). Then the 2nd statement bolds the selected characters - assuming you knew the surrounding text to be bold (probably the opposite but it's just an example).

    You might have to be careful which character you select for copying attributes. While the one just before the insertion point is the most convenient, it may have some "direct" formatting applied to it that is different than the text level it's contained in.

    The length is not hard to get since, per Jefferson's example, you have the clipboard contents in a string. LEN(string) solves that issue. Instead of
    Length:=4
    you could have
    Length:=LEN(string)

    Some thoughts to get started.

    Fred

  8. #8
    Bronze Lounger IanWilson's Avatar
    Join Date
    Dec 2000
    Location
    Bristol, United Kingdom
    Posts
    1,523
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Recording a macro for paste unformatted (2000)

    It sounds to me as though it may be easier just to put up with using the few extra mouse clicks it takes to go Edit - Paste Special - Unformatted text. But isn't the lack of consistency between different Office components frustrating! <img src=/S/bummer.gif border=0 alt=bummer width=15 height=15>

    Ian

  9. #9
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Recording a macro for paste unformatted (2000)

    Ian,

    If you don't have much stuff to change to the surrounding text, here's another approach:
    -select the text which you want the pasted text to look like (you've already done the pasting and want to change it's format)
    - click on the paint brush icon and "paint" over the pasted text by dragging the mouse over the pasted text with the left button down. This will make the pasted text look like what you selected

    Once you let go of the mouse button, your paint brush disappears. There is no limit how much you can paint (ie, drag over) as long as it's all adjacent. If you have lots of text to paint over and it's not all adjacent, double click the paint brush. You then need to hit the Escape key or click the brush again to get rid of the brush.

    And wouldn't you know it, VBA records nothing as you do this.

    Another trick I learned on the lounge: select the text you want the pasted text to look like (as above) and copy it to the clipboard. Now select the pasted text. Use CTRL+SHIFT+v (not CTRL+v) and you will paste the format of what you copied to the clipboard, not the actual text and it's format.

    In a way, this latter item is like the paintbrush. One difference is that you can move around, add more text, do other things. The format of the copied text is still available with CTRL+SHIFT+v. The actions of the paint brush with the double click are more limited in terms of things you can do in between painting.

    And wouldn't you know it, VBA does NOT record the CTRL+SHIFT+v action either!

    Fred

  10. #10
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Recording a macro for paste unformatted (2000)

    Here's the thread that contains the macro that you need. I still haven't made it any better, no time. HTH --SAM
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  11. #11
    New Lounger
    Join Date
    Jun 2002
    Location
    Lisbon, Portugal
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Recording a macro for paste unformatted (2000)

    In August 2002, Sammy wrote:
    "Here's the thread that contains the macro that you need. I still haven't made it any better, no time. HTH --SAM."
    Indeed Sammy even sent me the macro direct, for which I thank him.
    However, as a totally VB-ignorant user, I still find it difficult to transfer from one PPT project to another and to use.
    I also need an easy-to-use "paste formatted" shortcut.
    In fact, I'm even hoping that a senior moderator, or Woody himself is listening, not to mention Microsoft.
    Has anyone got idiot-proof solutions to these problems?

  12. #12
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: Recording a macro for paste unformatted (2000)

    Could you be more specific about your question - I don't want to bore you by answering the wrong thing.

    Cheers
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  13. #13
    3 Star Lounger
    Join Date
    Dec 2002
    Location
    USA
    Posts
    397
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Recording a macro for paste unformatted (2000)

    You should probably create an add-in for the macro. Add-ins are really easy to do if you just follow the instructions at http://www.rdpslides.com/pptfaq/FAQ00031.htm.

    At the very end, you'll see that it says this:
    ' This is just some silly example code. You'd put your real working code here to do whatever
    ' it is that you want to do
    MsgBox "Will you PLEASE stop clicking me? I have a headache already!"

    So basically, you just follow the instructions -- create a new module, copy/paste all the code listed into the module, then replace those three lines I mentioned with your existing macro code. Then follow the rest of the instructions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •