?
Solved

VBA loop code adding an extra slide

Posted on 2013-11-21
1
Medium Priority
?
456 Views
Last Modified: 2013-11-22
I have written some VBA code to create an agenda in powerpoint based on the entries of a user form. I have coded a loop to format the agenda, and that is all working fine, but it keeps adding a slide at the end of the Agenda. So, I put in a line to delete that slide, but the line doesn't always work - sometimes it does and sometimes it gives me an error message. I think I've gone wrong somewhere in the loop but I'm not sure where? I've pasted the code below (stripped out the irrelevant formatting).

Set s_ag = ppt.Slides.AddSlide(ActiveWindow.Selection.SlideRange.SlideIndex + 1, Agenda_layout)

        'Title
        s_ag.Shapes.Title.TextFrame.TextRange.Text = "Agenda"

        'Agenda text box
        Set Ag_text = s_ag.Shapes.AddTextbox(msoTextOrientationHorizontal, 157.8898, 134.9291, 422.9291, 100)
            Ag_text.TextFrame.TextRange.Font.Color.RGB = RGB(57, 50, 43)
                    Ag_text.TextFrame.TextRange.Text = Ag_tx1 & vbNewLine & Ag_tx2 & vbNewLine & Ag_tx3 & vbNewLine & Ag_tx4 _
                            & vbNewLine & Ag_tx5 & vbNewLine & Ag_tx6 & vbNewLine & Ag_tx7 & vbNewLine & Ag_tx8
                    If Ag_tx8.Text = "" Then
                    Ag_text.TextFrame.TextRange.Text = Ag_tx1 & vbNewLine & Ag_tx2 & vbNewLine & Ag_tx3 & vbNewLine & Ag_tx4 _
                            & vbNewLine & Ag_tx5 & vbNewLine & Ag_tx6 & vbNewLine & Ag_tx7
                    End If
                    If Ag_tx7.Text = "" Then
                        Ag_text.TextFrame.TextRange.Text = Ag_tx1 & vbNewLine & Ag_tx2 & vbNewLine & Ag_tx3 & vbNewLine & Ag_tx4 _
                            & vbNewLine & Ag_tx5 & vbNewLine & Ag_tx6
                    End If
                    If Ag_tx6.Text = "" Then
                        Ag_text.TextFrame.TextRange.Text = Ag_tx1 & vbNewLine & Ag_tx2 & vbNewLine & Ag_tx3 & vbNewLine & Ag_tx4 _
                            & vbNewLine & Ag_tx5
                    End If
                    If Ag_tx5.Text = "" Then
                        Ag_text.TextFrame.TextRange.Text = Ag_tx1 & vbNewLine & Ag_tx2 & vbNewLine & Ag_tx3 & vbNewLine & Ag_tx4
                    End If
                    If Ag_tx4.Text = "" Then
                        Ag_text.TextFrame.TextRange.Text = Ag_tx1 & vbNewLine & Ag_tx2 & vbNewLine & Ag_tx3
                    End If
                    If Ag_tx3.Text = "" Then
                        Ag_text.TextFrame.TextRange.Text = Ag_tx1 & vbNewLine & Ag_tx2
                    End If
                    If Ag_tx2.Text = "" Then
                        Ag_text.TextFrame.TextRange.Text = Ag_tx1
                    End If

            'Agenda rhombus (marker for each point)
            Set Ag_shp = s_ag.Shapes.AddShape(msoShapeRectangle, 96.37795, 546.5198, 28.34646, 28.34646)
                Ag_shp.IncrementRotation (45)
                    If Ag_tx8.Text = "" Then
                        Ag_shp.Top = 494.6457
                    End If
                    If Ag_tx7.Text = "" Then
                        Ag_shp.Top = 442.7717
                    End If
                    If Ag_tx6.Text = "" Then
                        Ag_shp.Top = 390.8977
                    End If
                    If Ag_tx5.Text = "" Then
                        Ag_shp.Top = 339.0237
                    End If
                    If Ag_tx4.Text = "" Then
                        Ag_shp.Top = 287.1497
                    End If
                    If Ag_tx3.Text = "" Then
                        Ag_shp.Top = 235.37795
                    End If
                    If Ag_tx2.Text = "" Then
                        Ag_shp.Top = 183.4016
                    End If


End If
Next

ActiveWindow.View.GotoSlide (ActiveWindow.Selection.SlideRange.SlideIndex + 1)

Set scurrent = ppt.Slides(ActiveWindow.Selection.SlideRange.SlideIndex)
Set Ag_textcurrent = Ag_text
  paracount = Ag_textcurrent.TextFrame.TextRange.Paragraphs.Count
    For x = paracount To 1 Step -1
        Set snew = scurrent.Duplicate(1)
            With Ag_shp
                .IncrementTop -51.87402
            End With
            Set Ag_textnew = Ag_textcurrent
            With Ag_textnew
                .TextFrame.TextRange.Paragraphs(x).Font.Bold = msoTrue
                .TextFrame.TextRange.Paragraphs(x + 1).Font.Bold = msoFalse
                .TextFrame.TextRange.Paragraphs(x).Font.Color.RGB = RGB(153, 0, 51)
                .TextFrame.TextRange.Paragraphs(x + 1).Font.Color.RGB = RGB(57, 50, 43)
            End With

    Next x

ActiveWindow.View.GotoSlide (ActiveWindow.Selection.SlideRange.SlideIndex + paracount)
ActiveWindow.Selection.Delete
0
Comment
Question by:jessica2013
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 23

Accepted Solution

by:
JSRWilson earned 1500 total points
ID: 39668675
You might do better to explain exactly what you have on the form and what you want to get as the outcome. Some of the logic is your code is almost certainly a lot more complex than it needs to be.

It looks like the extra slide would be set to the object var snew in which case you should be able to say snew.Delete to delete the extra slide
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Six Sigma Control Plans
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question