PDA

View Full Version : Solved: copy from clipboard and comment into notes



pir81
09-12-2011, 01:19 AM
Hi all,

Situation: I have to presentations and want to copy slides from a slave to a master. I also want to mark who prepared the slave in the master notes for each slide.

Thus I was wondering if there is a possibility to paste slides from clipboard into a current presentation and when the cntr+v happens, to ask who prepared the slides and then append in the notes of each of the slides, whaterver the users puts in.

I tried googeling a solution, but couldn't find anything. Maybe I am using the wrong terms.

Any suggestions are much appreciated.

John Wilson
09-12-2011, 02:54 AM
You don't mention the version you use which will be important.

I would suggesta google for REPURPOSE office commands

pir81
09-12-2011, 05:08 AM
John,
I am using Office 2010.

The repurpose command could work (at least from my understanding, by reading about it for the first time right now). I was just not able to find the name of the paste command, or is that just PASTE().

Also how can I know, how many slides are on the clipboard and are being pasted?

John Wilson
09-12-2011, 07:34 AM
It is just "Paste". A good tip is if you go to File > Options > customise ribbon

Find the command you need and hold the mouse over it for a few seconds the command name will pop up in brackets. They are not always so obvious as Paste.

Remember that in XML the case is important. paste is NOT the same as Paste!

pir81
09-12-2011, 01:40 PM
I am not sure, I am doing it correctly. I wrote a part of the code to test it, and if I run it by calling the macro it is fine, but it doesn't intercept. But that wouldn't matter that much actually, as I don't always want the name to be added (what happens if I paste only a graph, will it then also ask for a name? I can't find good reads on this)

I now just add a text box which is fine as well, but how do I get to count the number of slides on the pinwall?

Thank you in advance for any suggestions.

Sub Paste()
Dim owner As String
Dim count As Integer
Dim oShape As PowerPoint.Shape

count = ??? 'number of slides on pinwall
owner = InputBox(Prompt:="Input Slide Owner", _
Title:="ENTER OWNER", Default:="Who produced these slides")


Application.CommandBars.ExecuteMso ("Paste")
'but remember where you pasted it as it might be anywhere
'now loop through the newly added slides and add the text box

'set the textbox
Set oShape = ActivePresentation.Slides(1).Shapes.AddTextbox(msoTextOrientationHorizontal , 50, 50, 200, 50)
oShape.Name = "ownerTB"
With oShape
.Fill.Visible = msoTrue
End With

ActivePresentation.Slides(1).Shapes("ownerTB").TextFrame.TextRange.Text = owner
End Sub

pir81
09-13-2011, 05:53 AM
Dear all,
I have figured most of my questions out, but three:

1.)how does this paste replace the original paste (it doesn't seem to work - the popup box doesn't come up when using cntr+v or the paste button in powerpoint)
2.)my code works in a strange manner: if I step through the code, it adds the boxes, if I run it by calling the macro it doesn't add the boxes
3.) is there a command to get the active slide number, if you pointed with the cursor between two slides (in that case my programm throw an error at insertAfter = ActiveWindow.View.Slide.SlideIndex)

Thank you for your help

Sub Paste()
Dim owner As String

Dim newSlides As Integer
Dim afterSlide As Integer
Dim totalSlidesOld As Integer
Dim totalSlidesNew As Integer
Dim insertAfter As Integer
Dim i As Integer

Dim oShape As PowerPoint.Shape
i = 1

insertAfter = ActiveWindow.View.Slide.SlideIndex

totalSlidesOld = ActivePresentation.Slides.count

'who submitted the slides
owner = InputBox(Prompt:="Input Slide Owner", _
Title:="ENTER OWNER", Default:="Who produced these slides")

Application.CommandBars.ExecuteMso ("Paste")

totalSlidesNew = ActivePresentation.Slides.count
newSlides = totalSlidesNew - totalSlidesOld


'loop through the newly added slides
Do While i <= newSlides

'set the textbox (could be out as well?)
Set oShape = ActivePresentation.Slides(insertAfter + i).Shapes.AddTextbox(msoTextOrientationHorizontal, _
Left:=500, Top:=20, Width:=200, Height:=50)

oShape.Name = "ownerTB"
oShape.Fill.Visible = msoTrue
ActivePresentation.Slides(insertAfter + i).Shapes("ownerTB").TextFrame.TextRange.Text = owner

With oShape.TextFrame.TextRange
' MUST add text first
' else PPT ignores subsequent text formatting

.Font.Size = 20
.Font.Name = "Arial"
.Font.Bold = msoTrue
.Font.Italic = msoTrue
End With

i = i + 1
Loop



End Sub

John Wilson
09-13-2011, 06:25 AM
OK

1. That's not how to repurpose in 2007 on.
You need to add XML code to send the command to your code. There are tutorials out there on adding XML using CustomUIEditor which you will need to read.

XML

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<commands>
<command idMso="Paste" onAction="myPaste"/>
</commands>
</customUI>

vba

'Callback for Paste onAction
Sub myPaste(control As IRibbonControl, ByRef cancelDefault)
'code here
'cancelDefault = either true or false
End Sub
Your code works in step through only because you need to add DoEvents after the msoExecute


Application.CommandBars.ExecuteMso ("Paste")
DoEvents

pir81
09-17-2011, 06:35 AM
John thank you so much for your help! The code works but not the xml/vba, but I will post it under a new thread with the error message.

Thank you again a lot!