Solved

Set order of Slides

Posted on 2009-04-01
23
1,167 Views
Last Modified: 2012-05-06
Hi,
I'm using PowerPoint 2000.
I worked w/ an expert in an earlier question to set up the attached code. I have a VB.Net app that allows the user to drag and drop slides into the order that they want them to be in on the slide show. I use the Slide ID to keep up with the order and I save the ID's to a text file on the network when they save the slide order. Then the below code brings the file into powerpoint and puts the slides in the correct order.
My problem now is that when the slides are copied and deleted the Slide ID's get changed. This is a problem b/c I have to update these slides and if I don't have a solid identifier to go by then it's not going to work.
I tried to use the moveto method instead of the copy/delete, but I don't think it is available for PP2000.
Any suggestions?

Thx,
Dave

Sub SetOrder()
'
    Dim i As Integer
    Dim str As String
    
    For i = 1 To ActivePresentation.Slides.Count
        If str <> "" Then str = str & ", "
        str = str & ActivePresentation.Slides(i).slideID
    Next
    MsgBox "Slide ID's as detected are: " & vbCrLf & vbCrLf & str
    
    Dim sTemp
    Dim Value$
    Dim varSlide, iIndex As Integer
    Dim slideID As Integer
    
    Open "C:\Program Files\American Greetings\SlideShow\Slides\slide_id.txt" For Input As #3
    Line Input #3, Value$
    sTemp = Split(Value$, ",")
    For i = 1 To ActivePresentation.Slides.Count
        varSlide = CInt(sTemp(i - 1))
        ActivePresentation.Slides.FindBySlideID(varSlide).Copy
        ActivePresentation.Slides.Paste i
        ActivePresentation.Slides.FindBySlideID(varSlide).Delete
    Next
 
 
End Sub

Open in new window

0
Comment
Question by:coperations07
[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
  • 12
  • 11
23 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24045735
Dave

One option is I guess to calculate the new slide id order on insertion and save out to overwrite the text file, would that help?

Chris
0
 

Author Comment

by:coperations07
ID: 24049129
Well...that's about the only way I could think of to do it. I was hoping there was some other way to reorder the slides so they didn't lose their IDs.
You can reorder the slides in slide sorter view(not code), but it doesn't record anything in a macro when I try to do it. But, I have to think that if it can be done in the program then there is a way to do it through code...
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24049324
You would think so, but I believe that is why the moveto method was added to ppt 2007.  If you recall I did search extensively the last time for any alternative and couldn't find a method other than the cut/paste used above.

If you want to hold out of course for a 'better' answer of course then I will be interested to see what it is.  ALternatively if you wanted to implement the 'kludge' then let me know.

Chris
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:coperations07
ID: 24050246
Looks like I'll be going with the kludge...cool word by the way.  There's actually a machine here in the plant called the Kluge, German I think, I'll have to mess w/ the engineers about that.
I'll have to put some thought into what the best way will be to save the IDs.  I'll have to know what the old IDs are so I can match them up...
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24051010
I'll hopefully take care of it with your agreement and replace the conttents of slide_id.txt with the new data ready for the next run.

Is that ok?

Chris
0
 

Author Comment

by:coperations07
ID: 24051332
I don't think it's going to be as simple as overwriting the textfile.
I have a .Net app that is used to sort the slides and it sends the text file out the the network:
256,257,258,259
Then powerpoint will bring in the textfile and copy/delete into order when it opens. So the IDs will be something like: 260,261,262,263
Then there's another PP sub that updates the slides. Right now it finds the slide to update like this:
    currentSlide = ActivePresentation.Slides.FindBySlideID(256).SlideIndex
    ActiveWindow.View.GotoSlide Index:=currentSlide
So, the ID will have to be a variable that somehow knows that 260 is the "new" 256.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24052178
Okay understand this, I think there is a workaround!

Each slide can have a tag assigned which is saved with the file.  Therefore if the original application assigns the slideeid to the slide tag, (for example) OrigSlideID or whatever then on open all the slide tags can be read and the connection between new and old order maintained using that 'connection'.

Sound viable?

Chris
0
 

Author Comment

by:coperations07
ID: 24052650
Sounds interesting. It's a new concept for me though, so I'll have to look into it.

thx,
Dave
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24052935
Okay then, if I can help further then of course ask.  The ideal would seem to me to be if the master application writes the slide serial number to the tag ...slides(2).Tags("OrigSlideID") is what I used.

Now whenver re-ordering the slides on open read the slide ids and tags then whatever movements you make will always be right and reproducable / reversible, (using appropriate files of slide order) since the tag will be unchanged.

Chris
0
 

Author Comment

by:coperations07
ID: 24087606
I'm ready to get to work on this now. I had a bug in microsoft office, so I had to uninstall/reinstall. It's working now so hopefully I can get something done. I'll give this "tag" idea a try and see what it looks like.

thx,
Dave
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24094475
OKay then although you didn't ask I have just quickly tested an implementation as below.

For Each sldID In Array(5, 2, 3, 4, 1) is the array you would have in your text file and in my case had 5 slides ... I have assumed the number of entries in the text file reflects correctly the number of slides.  The numbers 1 to 5 are the values I stored in the tag for each sheet, and the sheet contents remain correctly ordered whatever I do.  I have included the file itself for information.

Chris
Sub resort_12345()
Dim sld As Slide
Dim dict As Object
Dim sldID As Variant
Dim sldIndex As Long
 
 
    Set dict = CreateObject("scripting.dictionary")
    For Each sld In ActivePresentation.Slides
        dict.Add sld.Tags("origslideid"), sld.SlideID
    Next
    For Each sldID In Array(5, 2, 3, 4, 1)
        Set sld = ActivePresentation.Slides.FindBySlideID(dict(CStr(sldID)))
        Debug.Print sld.SlideID & vbTab & sld.slideIndex
        sld.Copy
        ActivePresentation.Slides.Paste sldIndex + 1
        sld.Delete
    Next
    For Each sld In ActivePresentation.Slides
        Debug.Print sld.slideIndex & vbTab & sld.SlideID
    Next
    
End Sub

Open in new window

resort.txt
0
 

Author Comment

by:coperations07
ID: 24100335
Thanks man.
I plugged this code into my ppt and it gets an error after one loop through the first for loop.
Error Says: This key is already associated with an element of this collection.
I'm not familiar w/ the scripting.dictionary part, so I'm not real sure what it's doing. How might I fix this error?

Thx,
Dave
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24100723
I would expect that you have two slides with the same tag, try for example running a piece of code to read them out.

See below for a simple example ... and look for a duplicated number in the right hand 'column'.

Chris


Sub printOutNumbering()
Dim pres As Object
Dim str As String
Dim sld As Slide
 
    Set pres = ActivePresentation
    For Each sld In pres.Slides
        If str <> "" Then str = str & vbCrLf
        str = str & "Index: " & sld.slideIndex & " SlideID: " & sld.SlideID & " Slide Tag: " & sld.Tags("origslideid")
    Next
    MsgBox str
    
End Sub

Open in new window

0
 

Author Comment

by:coperations07
ID: 24101084
I've attached a screen shot of the messagebox I get. There doesn't appear to be any tags assigned to the slides.

ppt.doc
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24101209
That's the problem then ... you need to give each slide a tag that has the same name and is incremenatal ... in the case of my file I Attached they were 1 through 5.

I am in fact done for the night BUT if you would like then in teh morning I will make a script that will apply an incremenatal number to each slide as a tag?

Chris
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24101259
A quick untested hack to add the number to each slide is as attached ... remember this needs to be done by your master application at some point but should suffice for a test.

Chris
Sub addTag()
Dim pres As Object
Dim str As String
Dim sld As Slide
 
    Set pres = ActivePresentation
    For Each sld In pres.Slides
        sld.Tags.Add "OrigSlideID2", sld.slideIndex
    Next
    
End Sub

Open in new window

0
 

Author Comment

by:coperations07
ID: 24102184
"I am in fact done for the night BUT if you would like then in teh morning I will make a script that will apply an incremenatal number to each slide as a tag?"
Sounds good.

I've been playing around w/ this code some, but I don't think I'm getting anywhere.

Could you explain what this line does from your code?: sld.Tags.Add "OrigSlideID2", sld.slideIndex

I thought it was going to add the index # as a tag for each slide. But then I run the code that pops up the msgbox w/ index,slideid, tag and the tag is still blank. Am I thinking about this wrong?
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24104120
I tested, (quickly) the hack last night so used a different name.  for consistency with the other code use, unfortunately in my exhaustion I overllooked the name change when I posted:

This initialises the slide number references, (tags) as the slides are ordered at run-time

Chris.  
Sub addTag()
Dim pres As Object
Dim str As String
Dim sld As Slide
 
    Set pres = ActivePresentation
    For Each sld In pres.Slides
        sld.Tags.Add "OrigSlideID", sld.slideIndex
    Next
    
End Sub

Open in new window

0
 

Author Comment

by:coperations07
ID: 24108328
This is assigning the tags now.  The slides are being put in reverse order though, so I'm still working on debugging.

Now that the slides have tags how can I reference the tags?
The code below is what I had set up to go by the SlideIDs. Now I will either have to go by the slide tag or get the ID based on the tag.
Do you know what the max is for Slide IDs? They start at 256 and I'm already up to 350 just from testing.
    'Daily Excess
    currentSlide = ActivePresentation.Slides.FindBySlideID(312).SlideIndex
    ActiveWindow.View.GotoSlide Index:=currentSlide
    ActiveWindow.Selection.SlideRange.Shapes("WordArt 4").Select
    ActiveWindow.Selection.ShapeRange.TextEffect.Text = sDailyXS & "%"

Open in new window

0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24108533
The example routine I provided was set to try them in a different order as a stage of testing.  To put in the correct order use

    For Each sldID In Array(1, 2, 3, 4, 5)
instead of
    For Each sldID In Array(5, 2, 3, 4, 1)

Chris
Sub resort_12345()
Dim sld As Slide
Dim dict As Object
Dim sldID As Variant
Dim sldIndex As Long
 
 
    Set dict = CreateObject("scripting.dictionary")
    For Each sld In ActivePresentation.Slides
        dict.Add sld.Tags("origslideid"), sld.SlideID
    Next
    For Each sldID In Array(1, 2, 3, 4, 5)
        Set sld = ActivePresentation.Slides.FindBySlideID(dict(CStr(sldID)))
        Debug.Print sld.SlideID & vbTab & sld.slideIndex
        sld.Copy
        ActivePresentation.Slides.Paste sldIndex + 1
        sld.Delete
    Next
    For Each sld In ActivePresentation.Slides
        Debug.Print sld.slideIndex & vbTab & sld.SlideID
    Next
    
End Sub

Open in new window

0
 

Author Comment

by:coperations07
ID: 24108900
I just had to reverse the order that my slides were being saved in.  When a slide is cut and pasted it takes over the #1 index and apparently pushes the other slides down. 1,2,3 ends up 3,2,1...
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 24109265
Sorry but i'm confused.

If the ppt file was initialised as in teh code I supplied then the tags are numbered 1 to x from the first slide to the last.

If you use the indexing demonstrated in the script supplied earlier, (reproduced below) then all arrangements are with reference to the first order so

    For Each sldID In Array(1, 2, 3, 4, 5)
will put them in the same order as that when the tags were assigned.
    For Each sldID In Array(5, 4, 3, 2, 1)
will reverse the order and
    For Each sldID In Array(1, 4, 3, 2, 5)

Will be something else BUT still with relation to the original order.

Chris
    For Each sldID In Array(5, 2, 3, 4, 1)
        Set sld = ActivePresentation.Slides.FindBySlideID(dict(CStr(sldID)))
        Debug.Print sld.SlideID & vbTab & sld.slideIndex
        sld.Copy
        ActivePresentation.Slides.Paste sldIndex + 1
        sld.Delete
    Next

Open in new window

0
 

Author Closing Comment

by:coperations07
ID: 31565369
Thanks for the help. I think this is going to work. Sorry about the delayed response. I got pulled off of this for a while.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video teaches viewers how to fit pictures into slides, crop and remove backgrounds, and alter photos to look more professional.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

691 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