I am using the following code to export the data from the data provider to excel file. While scheduling the report on the BCA i am selecting this as custom macro. The report is scheduled to run daily.
The Problem is that the report runs fine the first time and creates a excel file with the data. When it runs next time it deletes the previous file but does not create a new one.
Sub Document_ExportCSV()
Dim bodoc As busobj.Document
Dim boDP As busobj.DataProvider
Dim strOutputFileName As String
Set bodoc = ActiveDocument
Set boDP = bodoc.DataProviders.Item(1)
strOutputFileName = "\\ shared drive name\Business Objects\Excelfile.xls"
intReturnCode = boDP.ConvertTo(boExpExcel, 1, strOutputFileName)
End Sub
You are not deleting the Excel file anywhere in your code :? So, it should simply overwrite the Excel sheet. When I tried your code, the same happened!! Then, why it is different for you? Is it b’cos of BCA
If the Excel file is open, then it will give error!!
If you are interested in the report itself, rather than DP, you can try this logic
Dim x As Boolean
Filename = “C:\XXX\default.xls”
x = rep.ExportAsText(Filename)
Our reports(may be Excel sheets) are not behaving strange with this…
I have already searched the BOB but with not much succes. I ran the macro on desktop and it gave me an error saying that file is already open. Would you please send me the code to kill the existing file. The requirement is to overwrite the existing file each time the report runs on the BCA.