BusinessObjects Board

Run VBA macro when opening a report or it's refreshed

In Access if I create a macro called “autoexec”, it executes when I open that Access database. Does anyone know if there is something similar in Business object macros that allows me to execute a macro when I open the report or when I refresh it?

I know that I can configure the report to refresh it automaticaly when I open it (clicking in a checkbox in Tools > Options > Save) but I don’t know how to execute a macro that I have created inside the report to run it when I open the report or when I have refreshed it.

In my company, we are running Business Objects 6.1…Yes it’s obsolete, but it’s what we have.

Thanks in advance

juagar (BOB member since 2018-01-31)

Obsolete is a very polite word for 6.1 :lol:

Have a look through this:

That’s the only resource I could find.


I know nothing about Business Objects 6.1.

In BOXIR2 & BO 3.1 you may use the Document_Open() event.

SuKA (BOB member since 2018-10-20)

Thanks SuKa for your answer.
So If I understand you well, if I create a macro called Document_Open with the following code:

Sub Document_Open()
End Sub

It will execute just when I open the report, even from the command line. That’s right?

I would like to launch some reports from command line and I want to save the results when they have refreshed. I think that would be the best approach if it works because I don’t have access BCA to do something similar.

juagar (BOB member since 2018-01-31)

I have tried the code I wrote in my last post and it didn’t work when it was inside a module. If I select the document, I see there are some events I can use. I select for example AfterRefresh and I write the following code and I have an error:

Private Sub Document_AfterRefresh()

    ThisDocument.SaveAs ("C:\Result.xls")
End Sub
Runtime error 10 - This funtion cannot be executed at this time

I have tried saving the result in .txt and I get the same error.
If I execute the code directly from de VBA editor, it works, it saves the document in xls or txt without problem, but it doesn’t work when is launched by the event.

Does anyone know why I get that runtime error?
Thanks in advance!

juagar (BOB member since 2018-01-31)

Are your code in the ThisDocument class? In a simple standard VBA module it will not be executed on open event.
From your next post I see you have found the Document_AfterRefresh event. At the same location you shold see the Open event too. If you click on it, a new empty “Private Sub Document_AfterRefresh()” procedure will be placed into the VBE editor. Place your code there.

SuKA (BOB member since 2018-10-20)

Sorry, you should get an empty “Private Sub Document_Open()” proc, of course.

SuKA (BOB member since 2018-10-20)