Only if - as I mentioned above - you want the results of the query, and not the output from the report. In that case, yes. But you don’t work with a document or report, you work with a data provider.
There is no ExportAsCSV function call.
Sub 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 = "C:\CSVOutput.csv"
intReturnCode = boDP.ConvertTo(boExpAsciiCSV, 1, strOutputFileName)
End Sub
There is no way to export (save as) a report as a CSV directly.
I have a document that contains 4 reports. The first 3 should be saved to three different text files and the 4th should be saved as a pdf? How do I change the code that takes the active document and saves it as text, to make it do what I need it to do (will be attending the macro class in March).
One way of doing it is, before saving it as PDF, delete the first three tabs and use the “ExportAsPDF”. It will save only the remaining tab page as PDF. And, Don’t save your report at the end.
Why go thru the process of deleting the reports?? If you are sure there will always be 4 reports then just use the following.
Sub exporting()
ActiveDocument.Reports(1).ExportAsText ("C:\" & ActiveDocument.Reports(1).Name)
ActiveDocument.Reports(2).ExportAsText ("C:\" & ActiveDocument.Reports(2).Name)
ActiveDocument.Reports(3).ExportAsText ("C:\" & ActiveDocument.Reports(3).Name)
ActiveDocument.Reports(4).ExportAsPDF ("C:\" & ActiveDocument.Reports(4).Name)
End Sub
Also look here for an add-in that does something similar.
There is a VB add-in floating around in here that will let you export the report in PDF, Excel, or TXT format. Check out the code samples area. Sorry I don’t have the link handy.
Read this topic, for one. That is essentially what was discussed. If you look at the code samples, they are all for saving the report as various output formats, not the data provider cubes.
Umm, I think that is a hard way of doing this. In VBA, the option “ExportAsText” saves your report tab, not the data cube. Been doing that on some reports for a while now.
Ya, even though it says export, that is the same as save as Text.
So basicly, for testing of your format you can manually save as text and see what the output will look like. Not sure on the side by side, never done that before.
Text does not support formatting. You’ll get the data from the report, but the positioning will be limited, at best.
Read them again. When you see a call to ConvertTo, it is being applied to the cube (data provider). When you see a call to ExportAsText or ExportAsPDF that is being applied to the report (or document, if available).
I understand; it can be confusing. The menu item to save the data provider (cube) is Export, while the menu item to save a report as text is Save As. But the VBA equivalents are:
Export => ConvertTo()
Save As => ExportAs{Type}
… where {Type} can be Text, RTF, PDF, or HTML.
seems very interesting add-in. unfortunately, when i tried to reach out Avaski’s donwload page, its stopped me saying unauthorized entry kind of IE message.
But i am desparately looking forward a kind of code. hope it wold contains creating New worksheet in already existing excel file.