Hi Paul,
thank you for your advice. The shorter reference doesn't work either, so your belief that MyFiles has to be open to make the getLabel function catch the shape names seems to be true. This is bad news. I dislike the idea of having MyFiles open all time as it makes it difficult to manage which presentation is the active one when the macros copy shapes from one to the other. Is there any other way to give the user the possibility to name his selection and make these names visible on the toolbar?
This is the code I used for the copy and paste from a to b and back, including the input box to rename shape names. As the shape names seem to be not the ideal way to solve it, that part seems to be obsolete now, but maybe I could name something else in a similar way ...
Public Sub Callback3(control As IRibbonControl)
Dim trg As Presentation
Dim sld As Slide
Dim target As Presentation
Dim shp As Shape
Dim Message As String
Dim Title As String
Dim Default As String
Dim MyValue3 As String
On Error GoTo err
If ActiveWindow.Selection.ShapeRange.Count < 1 Then
MsgBox "Please select a shape"
Exit Sub
End If
'Create an InputBox
Message = "Please give your selection a name (please use letters and numbers only, and no blanks)"
Title = "Add to MyFiles"
Default = "ObjectName"
MyValue3 = InputBox(Message, Title, Default)
'Let the user's input define the name
For Each shp In ActiveWindow.Selection.ShapeRange
shp.Name = MyValue3
Next
'Copy the selected objects
ActiveWindow.Selection.ShapeRange.Copy
'Open the target presentation
Set target = Application.Presentations.Open("C:\Users\Chef\Desktop\MyFiles.pptx")
Set trg = Presentations("MyFiles.pptx")
'Go to the wanted slide
ActiveWindow.View.GotoSlide (3)
'Select all shapes on the slide
trg.Slides(3).Shapes.SelectAll
'Delete what has been stored there
ActiveWindow.Selection.ShapeRange.Delete
'Go to target slide and paste
Set sld = ActiveWindow.View.Slide
sld.Shapes.Paste
'Close the target presentation
With Application.Presentations("MyFiles.pptx")
.Save
.Close
End With
Exit Sub
err:
MsgBox "Select at least one shape"
End Sub
And getting it back:
Public Sub Callback8(control As IRibbonControl)
Dim src As Presentation
Dim trg As Slide
Dim shp As Shape
Dim target As Presentation
'Open the source presentation
Set target = Application.Presentations.Open("C:\Users\Chef\Desktop\MyFiles.pptx")
Set src = Presentations("MyFiles.pptx")
'Go to the wanted slide
ActiveWindow.View.GotoSlide (3)
'Select all shapes on the slide
src.Slides(3).Shapes.SelectAll
'Copy the whole selection
ActiveWindow.Selection.ShapeRange.Copy
'Close the source presentation
With Application.Presentations("MyFiles.pptx")
.Close
End With
'Go to target slide and paste
Set trg = ActiveWindow.View.Slide
trg.Shapes.Paste
End Sub
Is it a possibility to work with five different files (each with only one slide) and let the user define their names via Input box, which then is caught and displayed on the ribbon by the getLebel function or would it come to exactly the same problem - the files have to be open?