none
how to get the name of a slide in the edit window

    Question

  • Hi, 

    I'm trying to write a vc++ program to get the name of ppt slide in the edit window.

    now, I have only figured out how to get the name of a slide in the slide show window.

    that is:

    presentation = app.GetActivePresentation();

    slideshowwindow = presentation.GetSlideShowWindow();

    view = slideshowwindow.GetView();

    slide = view.GetSlide();

    slidename = slide.GetName();

    but I don't know how to get the slide name in the edit window.

    anyone can give a hint? Thanks!

    I am using VC++2010 & powerpoint 2007

    Friday, April 26, 2013 7:19 AM

Answers

All replies

  • I tried to build a program to get the current slide name when someone is running/editing a ppt slideshows. 
    My strategy is to probe the structure of Presentations & SlideShowWindows  & Slides every 500ms.
    in most of the time, it works good. But when I open a modal dialogue box in the PowerPoint (for example, an open-file dialogue box), a COleException would occur, no matter which line it is running into when the dialogue opens.

    I have no idea how to solve it, anyone can help me?


    my code is as follow. And I am using PowerPoint 2007 and VC++ 2010.
    while(1)
    {
        presentations = m_app.GetPresentations();
    
        int n = presentations.GetCount();
     
        if(n>0)
        {
            presentation = m_app.GetActivePresentation();
            CString p_name = presentation.GetName();
            printf("ppt = %s\n", p_name);
    
            slides = presentation.GetSlides();
            int n_slides = slides.GetCount();
            printf("%d slides\n", n_slides);
    
            slideshowwindows = m_app.GetSlideShowWindows();
            int n_slideshowwindows = slideshowwindows.GetCount();
    
            if(n_slideshowwindows>0)
            {
                printf("in presenting\n");
                slideshowwindow = presentation.GetSlideShowWindow();
                view = slideshowwindow.GetView();
                long state = view.GetState();
                if(state != 5)
                {
                    slide = view.GetSlide();
                    CString s_name = slide.GetName();
                    printf("%s is current slide\n", s_name);
                }
            }
            else
            {
                DocumentWindow DW = m_app.GetActiveWindow();
                long viewtype = DW.GetViewType();
                printf("viewtype = %d\n", viewtype);
                if(viewtype == 0x09/*ppViewSlide*/)
                {
                    Selection selection = DW.GetSelection();
                    long seletype= selection.GetType();
                    //printf("Selection type = %d\n", seletype);
    
                    if(seletype == 1/*ppSelectionSlide*/)
                    {
                        SlideRange sliderange = selection.GetSlideRange();
                        int n_selected = sliderange.GetCount();
                        //printf("n_selected = %d\n", n_selected);
    
                        if(n_selected==1)
                        {
                            CString s_name = sliderange.GetName();
                            printf("Current editing slide = %s\n", s_name);
                        }
                    }
                }
                printf("not in presenting\n");
            }
    
        }
         printf("\n");
         Sleep(500);
    }


    Saturday, April 27, 2013 4:52 AM
  • Hi Vic.W,

    Thank you for posting in the MSDN Forum.

    Since I'm not familiar with C++, I'll show you how to get the slide's name with VBA in below section.

    Sub test()
        
        Dim pres As Presentation
        Set pres = ActivePresentation
        
        'Both the 2 lines below can work.
        MsgBox Application.ActiveWindow.View.Slide.Name
        MsgBox pres.Windows.Item(1).View.Slide.Name
        
    End Sub

    Related References:

    C++ have different syntax from VBA, so probably you'll need to change app.ActiveWindow to app.GetActiveWindow() in your code. The same goes for other properties.

    Please feel free to let me know if you need any further help.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 29, 2013 5:02 AM
    Moderator
  • Thanks Quist,

    I tried to implement it in c++ code, and it works well.

    But I met another problem: During the running of the code( after app.CreateDispatch), if I open a modal dialogue box in the PowerPoint (for example, an open-file dialogue box), a COleException would occur, and the whole program would crash. No matter which line the program is running into. GetActivePresentation,GetActiveWindow,GetSlide,GetName...all these function would crash, when there is a a modal dialogue box over the powerpoint window.

    I have no idea how to solve it. Would the VB program crash in the same condition?

    Vic



    Monday, April 29, 2013 2:20 PM
  • Hi Vic.W,

    Thank you for your last reply.

    Based on my knowledge, you can use dialogue in automation program. Since the 2nd question is a new question, I suggest you open a new thread with code that cause exceptions.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, May 1, 2013 7:01 AM
    Moderator