Click here to Skip to main content
15,898,036 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
HI Friends,

We can activate a word document like :
targetDoc.Activate();


What is the API for Powerpoint document activation? I tried some of this but no result:

C#
foreach (PPT.Presentation pp in ppApp.Presentations)
{
    if (pp.Name == TargetFileName)
    {
        pp.Application.Activate();
    }
}


[edit]Tags, braces indent - OriginalGriff[/edit]
Posted
Updated 30-May-11 22:47pm
v2
Comments
Sergey Alexandrovich Kryukov 31-May-11 4:44am    
Add a tag: Powerpoint.
--SA
Tarun.K.S 31-May-11 4:55am    
I have updated the answer. I have also added a for-each version.

Guys,
i tried this, it will also work ....

C#
string selePPT = comboBox1.SelectedItem.ToString();
            string before = ppApp.ActiveWindow.Caption;
            string after = "";
            foreach (PPT.DocumentWindow pp in ppApp.Windows)
            {
                if (pp.Caption == selePPT)
                {
                    pp.Activate();
                    after = ppApp.ActiveWindow.Caption;
                    MessageBox.Show(before + "  " + after);
                }
            }
 
Share this answer
 
Comments
Tarun.K.S 31-May-11 5:43am    
Cool! 5+
Hi prasad,

Do this:

C#
for(int i=1; i <= ppApp.Presentation.Count; i++)
{
 if(ppApp.Presentations[i].Name == TargetFileName)
 {
  ppApp.Presentations[i].Windows[i].Activate();
 }
}


If you want to use the foreach only, then use an integer i;

int i = 0;
C#
foreach (PPT.Presentation pp in ppApp.Presentations)
                          { 
                              i = i + 1;
                              if (pp.Name == TargetFileName)
                              {
                                  pp.Windows(i).Activate();
                              }
                          }



Hope it helped. :)
 
Share this answer
 
v3
Comments
Tarun.K.S 31-May-11 5:01am    
I know in my first revision I made a mistake by giving a presentation name instead of the index. Requesting to re-vote as this does solve the question. Thank you.
2000 P 31-May-11 5:51am    
Thank you Tarun :)
Tarun.K.S 31-May-11 5:53am    
Phew! Thanks prasad for accepting the answer :), don't know who downvoted it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900