From: Steve Rindsberg on 19 Jan 2006 05:09 In article <uOKnT9QHGHA.1452(a)TK2MSFTNGP11.phx.gbl>, Bob wrote: > I'm trying to write a macro that creates a new slide at the end of a > presentation, creates a text box on it, and pastes text into the text box. > Here's the pertinent code: > ActiveWindow.View.GoToSlide(NumSlides + 1) will take you to your new slide But to expand on David's suggestion, it's good to learn to work with objects instead of the current selection. It saves all kinds of teethmarks on your hide. Try something like this instead (watch out for linebreaks) Dim oSl as Slide Dim oSh as Shape Dim NumSlides as Long ' Rather than integer ' etc Set oSl = ActivePresentation.Slides.Add(Index:=NumSlides + 1, _ Layout:=ppLayoutText) With oSl .Layout = ppLayoutBlank .FollowMasterBackground = msoFalse set oSh = .Shapes.AddTextbox(msoTextOrientationHorizontal, _ 0, 0, 720, 36) With oSh .TextFrame.WordWrap = msoTrue (other properties) .TextRange.Font.Color.RGB = RGB(0,0,0) ' etc End With ' oSh End with ' oSl Another advantage to using objects rather than selection is that the same code will work in edit or slideshow mode, and you don't have to worry what slide's in view. ----------------------------------------- Steve Rindsberg, PPT MVP PPT FAQ: www.pptfaq.com PPTools: www.pptools.com ================================================
From: Bob on 19 Jan 2006 16:34 Thanks for all of the suggestions - they worked! I used objects and was able to get the macro working. Well, until I ran into one odd problem. When I run the macro in a short presentation (less than 10 or 11 slides), it does exactly what I want it to: 1) Gather all comments. 2) Insert new slide at end. 3) Insert text box on new slide. 4) Insert list of comments. If I run the macro in a longer presentation, it gathers the comments and inserts a new slide at the end, but it then puts the text box on the *first* slide! It does put the comments in the new text box, but why is the text box added to the first slide, not to the last? Why does the length of the presentation matter? For reference, and for your use (if anyone wants it!), here's the "working" code: Sub Comments2Slide() Dim SlideThis As Slide Dim CommentThis As Comment Dim CommentList As String Dim NumSlides As Long Dim SlideWidth As Long Dim SlideHeight As Long Dim CommentSlide As Slide Dim CommentTextBox As Shape NumSlides = ActivePresentation.Slides.Count SlideWidth = ActivePresentation.Slides(1).Master.Width SlideHeight = ActivePresentation.Slides(1).Master.Height ' Gather comments.................... For Each SlideThis In ActivePresentation.Slides For Each CommentThis In SlideThis.Comments CommentList = CommentList & "Slide #" & SlideThis.SlideNumber & " - " & CommentThis.Text & vbCrLf Next CommentThis Next SlideThis ' Create new slide.................... Set CommentSlide = ActivePresentation.Slides.Add(Index:=NumSlides + 1, Layout:=ppLayoutText) With CommentSlide .Layout = ppLayoutBlank .FollowMasterBackground = msoFalse 'Create text box.................... Set CommentTextBox = ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHorizo ntal, 0, 0, SlideWidth, SlideHeight) With CommentTextBox .TextFrame.WordWrap = msoTrue .TextFrame.AutoSize = ppAutoSizeShapeToFitText .Fill.Transparency = 0# .Fill.Visible = msoTrue .Fill.Solid .Fill.ForeColor.RGB = RGB(255, 255, 255) .TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0) ' Put comments in text box.................... .TextFrame.TextRange.Text = CommentList .TextFrame.TextRange.Font.Name = "Arial Narrow" .TextFrame.TextRange.Font.Size = 10 End With End With End Sub
From: Steve Rindsberg on 19 Jan 2006 11:10 In article <OeqsoAUHGHA.2472(a)TK2MSFTNGP10.phx.gbl>, Bob wrote: > Thanks for all of the suggestions - they worked! I used objects and was > able to get the macro working. Well, until I ran into one odd problem. > When I run the macro in a short presentation (less than 10 or 11 slides), it > does exactly what I want it to: > > 1) Gather all comments. > 2) Insert new slide at end. > 3) Insert text box on new slide. > 4) Insert list of comments. > > If I run the macro in a longer presentation, it gathers the comments and > inserts a new slide at the end, but it then puts the text box on the *first* > slide! It does put the comments in the new text box, but why is the text > box added to the first slide, not to the last? Why does the length of the > presentation matter? Are you certain that's the problem? Your code for adding the text box is dealing with the current SELECTION again. Bad programmer. BAD! ;-) See the suggested change below: > Sub Comments2Slide() > Dim SlideThis As Slide > Dim CommentThis As Comment > Dim CommentList As String > Dim NumSlides As Long > Dim SlideWidth As Long > Dim SlideHeight As Long > Dim CommentSlide As Slide > Dim CommentTextBox As Shape > NumSlides = ActivePresentation.Slides.Count > SlideWidth = ActivePresentation.Slides(1).Master.Width > SlideHeight = ActivePresentation.Slides(1).Master.Height > ' Gather comments.................... > For Each SlideThis In ActivePresentation.Slides > For Each CommentThis In SlideThis.Comments > CommentList = CommentList & "Slide #" & SlideThis.SlideNumber & " - > " & CommentThis.Text & vbCrLf > Next CommentThis > Next SlideThis > ' Create new slide.................... > Set CommentSlide = ActivePresentation.Slides.Add(Index:=NumSlides + 1, > Layout:=ppLayoutText) > With CommentSlide > .Layout = ppLayoutBlank > .FollowMasterBackground = msoFalse > 'Create text box.................... Here's the problem > Set CommentTextBox = > ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHorizo > ntal, 0, 0, SlideWidth, SlideHeight) try this: Set CommentTextBox = CommentSlide.Shapes.AddTextbox(msoTextOrientationHorizo ntal, 0, 0, SlideWidth, SlideHeight) Watch the line breaks ... that should all be on one line > With CommentTextBox > .TextFrame.WordWrap = msoTrue > .TextFrame.AutoSize = ppAutoSizeShapeToFitText > .Fill.Transparency = 0# > .Fill.Visible = msoTrue > .Fill.Solid > .Fill.ForeColor.RGB = RGB(255, 255, 255) > .TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0) > ' Put comments in text box.................... > .TextFrame.TextRange.Text = CommentList > .TextFrame.TextRange.Font.Name = "Arial Narrow" > .TextFrame.TextRange.Font.Size = 10 > End With > End With > End Sub > ----------------------------------------- Steve Rindsberg, PPT MVP PPT FAQ: www.pptfaq.com PPTools: www.pptools.com ================================================
From: Bob on 20 Jan 2006 09:47 Arrggghhh.... I removed the ".Select" from the end of the line, but didn't rewrite the whole line. Bad editor. BAD! (woof, woof). Rewriting the line causes the macro now to place the text box on the last slide. More importantly, I understand why! What I don't understand is why the old code put the text box on the last slide in short presentations and on the first slide in longer presentations. Any ideas? BTW, thanks to your advice, I wrote a Word macro last night using discrete Dims and objects. It worked the first time! I will try to use objects, rather than selections, where possible in the future. Thanks! Bob "Steve Rindsberg" <abuse(a)localhost.com> wrote in message news:VA.0000204e.1414cb12(a)localhost.com... > In article <OeqsoAUHGHA.2472(a)TK2MSFTNGP10.phx.gbl>, Bob wrote: > > Thanks for all of the suggestions - they worked! I used objects and was > > able to get the macro working. Well, until I ran into one odd problem. > > When I run the macro in a short presentation (less than 10 or 11 slides), it > > does exactly what I want it to: > > > > 1) Gather all comments. > > 2) Insert new slide at end. > > 3) Insert text box on new slide. > > 4) Insert list of comments. > > > > If I run the macro in a longer presentation, it gathers the comments and > > inserts a new slide at the end, but it then puts the text box on the *first* > > slide! It does put the comments in the new text box, but why is the text > > box added to the first slide, not to the last? Why does the length of the > > presentation matter? > > Are you certain that's the problem? > Your code for adding the text box is dealing with the current SELECTION again. > Bad programmer. BAD! ;-) > > See the suggested change below: > > > Sub Comments2Slide() > > Dim SlideThis As Slide > > Dim CommentThis As Comment > > Dim CommentList As String > > Dim NumSlides As Long > > Dim SlideWidth As Long > > Dim SlideHeight As Long > > Dim CommentSlide As Slide > > Dim CommentTextBox As Shape > > NumSlides = ActivePresentation.Slides.Count > > SlideWidth = ActivePresentation.Slides(1).Master.Width > > SlideHeight = ActivePresentation.Slides(1).Master.Height > > ' Gather comments.................... > > For Each SlideThis In ActivePresentation.Slides > > For Each CommentThis In SlideThis.Comments > > CommentList = CommentList & "Slide #" & SlideThis.SlideNumber & " - > > " & CommentThis.Text & vbCrLf > > Next CommentThis > > Next SlideThis > > ' Create new slide.................... > > Set CommentSlide = ActivePresentation.Slides.Add(Index:=NumSlides + 1, > > Layout:=ppLayoutText) > > With CommentSlide > > .Layout = ppLayoutBlank > > .FollowMasterBackground = msoFalse > > > 'Create text box.................... > > Here's the problem > > > Set CommentTextBox = > > ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHorizo > > ntal, 0, 0, SlideWidth, SlideHeight) > > > try this: > > Set CommentTextBox = CommentSlide.Shapes.AddTextbox(msoTextOrientationHorizo > ntal, 0, 0, SlideWidth, SlideHeight) > > > Watch the line breaks ... that should all be on one line > > > With CommentTextBox > > .TextFrame.WordWrap = msoTrue > > .TextFrame.AutoSize = ppAutoSizeShapeToFitText > > .Fill.Transparency = 0# > > .Fill.Visible = msoTrue > > .Fill.Solid > > .Fill.ForeColor.RGB = RGB(255, 255, 255) > > .TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0) > > ' Put comments in text box.................... > > .TextFrame.TextRange.Text = CommentList > > .TextFrame.TextRange.Font.Name = "Arial Narrow" > > .TextFrame.TextRange.Font.Size = 10 > > End With > > End With > > End Sub > > > > ----------------------------------------- > Steve Rindsberg, PPT MVP > PPT FAQ: www.pptfaq.com > PPTools: www.pptools.com > ================================================ > >
From: Steve Rindsberg on 20 Jan 2006 03:40 In article <egH98BdHGHA.1088(a)tk2msftngp13.phx.gbl>, Bob wrote: > Arrggghhh.... I removed the ".Select" from the end of the line, but didn't > rewrite the whole line. Bad editor. BAD! (woof, woof). > > Rewriting the line causes the macro now to place the text box on the last > slide. More importantly, I understand why! What I don't understand is why > the old code put the text box on the last slide in short presentations and > on the first slide in longer presentations. Any ideas? Not offhand. I think it actually may have been putting the text box on whatever slide you were on when you ran the code and that the length of the presentation was a red herring. O no. I've set off a food thread! > BTW, thanks to your advice, I wrote a Word macro last night using discrete > Dims and objects. It worked the first time! I will try to use objects, > rather than selections, where possible in the future. > > Thanks! > > Bob > > "Steve Rindsberg" <abuse(a)localhost.com> wrote in message > news:VA.0000204e.1414cb12(a)localhost.com... > > In article <OeqsoAUHGHA.2472(a)TK2MSFTNGP10.phx.gbl>, Bob wrote: > > > Thanks for all of the suggestions - they worked! I used objects and was > > > able to get the macro working. Well, until I ran into one odd problem. > > > When I run the macro in a short presentation (less than 10 or 11 > slides), it > > > does exactly what I want it to: > > > > > > 1) Gather all comments. > > > 2) Insert new slide at end. > > > 3) Insert text box on new slide. > > > 4) Insert list of comments. > > > > > > If I run the macro in a longer presentation, it gathers the comments and > > > inserts a new slide at the end, but it then puts the text box on the > *first* > > > slide! It does put the comments in the new text box, but why is the > text > > > box added to the first slide, not to the last? Why does the length of > the > > > presentation matter? > > > > Are you certain that's the problem? > > Your code for adding the text box is dealing with the current SELECTION > again. > > Bad programmer. BAD! ;-) > > > > See the suggested change below: > > > > > Sub Comments2Slide() > > > Dim SlideThis As Slide > > > Dim CommentThis As Comment > > > Dim CommentList As String > > > Dim NumSlides As Long > > > Dim SlideWidth As Long > > > Dim SlideHeight As Long > > > Dim CommentSlide As Slide > > > Dim CommentTextBox As Shape > > > NumSlides = ActivePresentation.Slides.Count > > > SlideWidth = ActivePresentation.Slides(1).Master.Width > > > SlideHeight = ActivePresentation.Slides(1).Master.Height > > > ' Gather comments.................... > > > For Each SlideThis In ActivePresentation.Slides > > > For Each CommentThis In SlideThis.Comments > > > CommentList = CommentList & "Slide #" & SlideThis.SlideNumber & > " - > > > " & CommentThis.Text & vbCrLf > > > Next CommentThis > > > Next SlideThis > > > ' Create new slide.................... > > > Set CommentSlide = ActivePresentation.Slides.Add(Index:=NumSlides + > 1, > > > Layout:=ppLayoutText) > > > With CommentSlide > > > .Layout = ppLayoutBlank > > > .FollowMasterBackground = msoFalse > > > > > 'Create text box.................... > > > > Here's the problem > > > > > Set CommentTextBox = > > > > ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHorizo > > > ntal, 0, 0, SlideWidth, SlideHeight) > > > > > > try this: > > > > Set CommentTextBox = > CommentSlide.Shapes.AddTextbox(msoTextOrientationHorizo > > ntal, 0, 0, SlideWidth, SlideHeight) > > > > > > Watch the line breaks ... that should all be on one line > > > > > With CommentTextBox > > > .TextFrame.WordWrap = msoTrue > > > .TextFrame.AutoSize = ppAutoSizeShapeToFitText > > > .Fill.Transparency = 0# > > > .Fill.Visible = msoTrue > > > .Fill.Solid > > > .Fill.ForeColor.RGB = RGB(255, 255, 255) > > > .TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0) > > > ' Put comments in text box.................... > > > .TextFrame.TextRange.Text = CommentList > > > .TextFrame.TextRange.Font.Name = "Arial Narrow" > > > .TextFrame.TextRange.Font.Size = 10 > > > End With > > > End With > > > End Sub > > > > > > > ----------------------------------------- > > Steve Rindsberg, PPT MVP > > PPT FAQ: www.pptfaq.com > > PPTools: www.pptools.com > > ================================================ > > > > > ----------------------------------------- Steve Rindsberg, PPT MVP PPT FAQ: www.pptfaq.com PPTools: www.pptools.com ================================================
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Can we embed movie(mpg/mpeg) file in powerpoint? Next: Sales Funnel Template Slide |