Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

error at exporting graphs to powerpoint

hello

I have a qv file with a lot of sheets, each one with one graph. I need to export all the graphs to a powerpoint file, each graph in one slide. I use ths code:

sub ppt

    Set PPApp = CreateObject("Powerpoint.Application")

    PPApp.Visible = True ' Create a presentation

    Set PPPres = PPApp.Presentations.Add

    hojas = Activedocument.NoOfSheets

    for i=1 to hojas-1

        set s=Activedocument.Sheets(i)

        charts=s.GetGraphs

        Set PPSlide = PPPres.Slides.Add(1, 1)

        PPSlide.Shapes(1).Delete ' removes the title

        PPSlide.Shapes(1).Delete ' removes the text box

        charts(0).CopyBitmapToClipboard

        with PPSlide.Shapes.Paste

            .Left = 0

            .Top = 30

            .Width=720

        end with

    next

    PPPres.SaveAs "C:\Trend_Charts.ppt"

    PPPres.Close

    PPApp.Quit

    Set PPSlide = Nothing

    Set PPPres = Nothing

    Set PPApp = Nothing

end sub

The problem is that it only copys the very first graph, and the macro paste it every times.

What am I doing wrong? Why it only copys the first graph in the first sheet???

Thanks in advance.

7 Replies
Not applicable
Author

Nobody can help me???

m_woolf
Master II
Master II

Should this line:

     charts(0).CopyBitmapToClipboard

say something like:

     charts(i).CopyBitmapToClipboard

Not applicable
Author

Thanks for yours responses

charts(0) isn´t the problem, because in each loop I change the sheet and in each sheet there are only one chart. I think that the problem is a time problem, I think that there is no time to copy in the clipboard, because if I put the sentence MsgBox(i) just before coping the chart, it works fine, so there is another question. Is there anyway to wait some time between loops???

Thanks

m_woolf
Master II
Master II

Try putting

Application.WaitForIdle

just before the CopyBitmapToClipboard line

Not applicable
Author

It doesn´t work

m_woolf
Master II
Master II

The API Guide says:

ActiveDocument.GetApplication.WaitForIdle

There are some posts on the forum about WaitForIdle not working in certain versions of QV.

There also some posts about using:

ActiveDocument.GetApplication.Sleep

Try either of these followed by a number: 1000.... I think this is milliseconds

Not applicable
Author

Hello.

Finally the problem was that I have to activate the sheet and wait there. This is the code that works

sub ppt

    Set PPApp = CreateObject("Powerpoint.Application")

    PPApp.Visible = True ' Create a presentation

    Set PPPres = PPApp.Presentations.Add

    hojas = Activedocument.NoOfSheets

    for i=hojas-1 to 1 step -1

        set s=Activedocument.Sheets(i)

        s.Activate

        Activedocument.GetApplication.Sleep 150

        Activedocument.GetApplication.WaitForIdle 1000

        charts=s.GetGraphs

        Set PPSlide = PPPres.Slides.Add(1, 1)

        PPSlide.Shapes(1).Delete ' removes the title

        PPSlide.Shapes(1).Delete ' removes the text box

        charts(0).CopyBitmapToClipboard

        with PPSlide.Shapes.Paste

            .Left = 0

            .Top = 30

            .Width=720

        end with

       

    next

    PPPres.SaveAs "C:\Export.ppt"

    PPPres.Close

    PPApp.Quit

    Set PPSlide = Nothing

    Set PPPres = Nothing

    Set PPApp = Nothing

end sub

Thanks to all