n12nja
09-09-2015, 04:25 AM
Hi guys - I'm hoping someone far more knowledgeable about VB will be kind enough to help me.
"TLDR Version - How do I replace this label with an activex version of a label added to the slide master
Dim mySh As Shape
ActivePresentation.Designs(1).SlideMaster.Shapes.AddLabel(msoTextOrientatio nHorizontal, 10, 10, 400, 50)
"
In context:
I am creating a powerpoint in which the user can enter text into a text box on the powerpoint while the show is running and it will then populate every slide a text label with what was typed.
I have successfully managed to get to the stage where it will find the slide with the text box on it - and upon the slide being changed to the next one it will then create a text label in the SlideMaster which displays on every slide.
The problem I now have is if the presentation was to be run again it will then recreate the text label - stacking them on top of each other. It sounds simple - all I should need to do is check if the label already exists - if it does amend it, if not create it.
When I try to check if the text label already exists - it seems the label is not successfully named and thus cannot be referred to. I think it is because it is creating a standard text label and not an activex control thus preventing it being referenced later by name (or if it is I'm not sure how)
Please find below my code
Dim waltInfo As String 'This string is used to store the value input during the show from textbox 'WaltMainBox which exists on one of the normal slides within the slideshow
Function ShapeNamed(sShapeName As String, oSl As Slide) As Shape 'this function finds if the 'shape is present and is used to check when the slide after the slide with the textbox on it has 'been shown
Dim oSh As Shape
For Each oSh In oSl.Shapes
If oSh.Name = sShapeName Then
Set ShapeNamed = oSh
Exit Function
End If
Next
End Function
Sub OnSlideShowPageChange()
Dim sldHeight As Single
sldHeight = ActivePresentation.PageSetup.SlideHeight
Dim sldWidth As Single
sldWidth = ActivePresentation.PageSetup.SlideWidth
Dim WaltCopy As Shape
Dim oSh As Shape
Set oSh = ShapeNamed("WaltMainBox", ActivePresentation.Slides(ActivePresentation.SlideShowWindow.View.Slide.Sli deIndex - 1))
If Not oSh Is Nothing Then
'the slide with the inputbox on it is found so transfer information from it to waltInfo
waltInfo = oSh.OLEFormat.Object.Text
Dim x As Long
Dim mySh As Shape
With ActivePresentation
' On each slidemaster in the presentation add the label
For x = 1 To .Designs.Count
Set mySh = _
.Designs(x).SlideMaster.Shapes.AddLabel(msoTextOrientationHorizontal, 10, 10, sldWidth - 20, 50)
mySh.Name = "WaltLabel" 'I hoped this would allow me to reference this label later but 'doesn't seem to help
With mySh.TextFrame.TextRange
.Font.Name = "Arial"
.Font.Size = 18
.Text = waltInfo
End With
Next
End With
End If
End Sub
Many thanks for any assistance you can give! =)
Darren
"TLDR Version - How do I replace this label with an activex version of a label added to the slide master
Dim mySh As Shape
ActivePresentation.Designs(1).SlideMaster.Shapes.AddLabel(msoTextOrientatio nHorizontal, 10, 10, 400, 50)
"
In context:
I am creating a powerpoint in which the user can enter text into a text box on the powerpoint while the show is running and it will then populate every slide a text label with what was typed.
I have successfully managed to get to the stage where it will find the slide with the text box on it - and upon the slide being changed to the next one it will then create a text label in the SlideMaster which displays on every slide.
The problem I now have is if the presentation was to be run again it will then recreate the text label - stacking them on top of each other. It sounds simple - all I should need to do is check if the label already exists - if it does amend it, if not create it.
When I try to check if the text label already exists - it seems the label is not successfully named and thus cannot be referred to. I think it is because it is creating a standard text label and not an activex control thus preventing it being referenced later by name (or if it is I'm not sure how)
Please find below my code
Dim waltInfo As String 'This string is used to store the value input during the show from textbox 'WaltMainBox which exists on one of the normal slides within the slideshow
Function ShapeNamed(sShapeName As String, oSl As Slide) As Shape 'this function finds if the 'shape is present and is used to check when the slide after the slide with the textbox on it has 'been shown
Dim oSh As Shape
For Each oSh In oSl.Shapes
If oSh.Name = sShapeName Then
Set ShapeNamed = oSh
Exit Function
End If
Next
End Function
Sub OnSlideShowPageChange()
Dim sldHeight As Single
sldHeight = ActivePresentation.PageSetup.SlideHeight
Dim sldWidth As Single
sldWidth = ActivePresentation.PageSetup.SlideWidth
Dim WaltCopy As Shape
Dim oSh As Shape
Set oSh = ShapeNamed("WaltMainBox", ActivePresentation.Slides(ActivePresentation.SlideShowWindow.View.Slide.Sli deIndex - 1))
If Not oSh Is Nothing Then
'the slide with the inputbox on it is found so transfer information from it to waltInfo
waltInfo = oSh.OLEFormat.Object.Text
Dim x As Long
Dim mySh As Shape
With ActivePresentation
' On each slidemaster in the presentation add the label
For x = 1 To .Designs.Count
Set mySh = _
.Designs(x).SlideMaster.Shapes.AddLabel(msoTextOrientationHorizontal, 10, 10, sldWidth - 20, 50)
mySh.Name = "WaltLabel" 'I hoped this would allow me to reference this label later but 'doesn't seem to help
With mySh.TextFrame.TextRange
.Font.Name = "Arial"
.Font.Size = 18
.Text = waltInfo
End With
Next
End With
End If
End Sub
Many thanks for any assistance you can give! =)
Darren