Solved

Set order of Slides

Posted on 2009-04-01
23
1,154 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
  • 12
  • 11
23 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:coperations07
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:coperations07
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
"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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Background   Certain code in VBA requires initialization, such as application events. The app initialization is often triggered by the Auto_Open sub which is a special procedure that runs when an add-in loads. More significantly, this sub does n…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This video teaches viewers how to fit pictures into slides, crop and remove backgrounds, and alter photos to look more professional.
This video teaches viewers how to create handouts from their slides and helps them decide how many slides to include per handout.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now