Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to know how to setup an autorun macro 1

Status
Not open for further replies.

simonjackson79

Technical User
Dec 23, 2003
31
0
0
GB
Hi,

I am using BO 5 and need to know how to setup a macro to do the following things when a report has been opened:

Refresh the report,
Export as a text file,
Save the report,
Close the report.

I need this to autorun, but have no idea how to do this.

Many thanks for your time,

Simon
 
Simon,

You need to do some vba programming, open the vba window, select this document and add the following code to the Document_Open event

dim Doc as Document
dim Rep as Report

set Doc = application.Documents.Item(1)
set Rep = Doc.Reports.Item(1)
Doc.Refresh
rep.ExportAsText("C:\Mydocs\Report1")
doc.save
application.quit


Feel free to as any questions
 
You're a star, I'll let you know if I have any problems.

Thanks again and have a good Christmas.

Simon
 
I would suggest a small change to DrSmyth's code. Instead of

Code:
set Doc = application.Documents.Item(1)

its better to use

Code:
set Doc = Application.ActiveDocument

The reason is if you have some kinda add-in then that may not always return reference to the document which is of interest to you.

One more thing you need to do is put the code in Document_Activate rather than Document_Open since you cannot get a reference to the document as it is still not opened i.e. it is in opening stage. So the best place is to put it in Document_Activate.

Good Luck
Sri
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top