There are plenty of examples in this forum if you read. Just do a keyword search like 'vb' or 'visual basic' 'vb export report', etc. If you still need help, email me your specific needs. Also, if you click on Impromptu help under macros you find some good info.
Have fun...
Paul
Here is some sample code below....
Dim objImpApp As Object
Dim objImpRep As Object
'Cognos
'Registry Function Prototypes
Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" _
(ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _
ByVal samDesired As Long, phkResult As Long) As Long
Declare Function RegQueryValueExStr Lib "advapi32" Alias "RegQueryValueExA" _
(ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, _
ByRef lpType As Long, ByVal szData As String, ByRef lpcbData As Long) As Long
Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
'Registry Specific Access Rights
Const KEY_ALL_ACCESS = &H3F
'Define severity codes
Const ERROR_SUCCESS = 0&
'Predefined Registry Class Constant
Const HKEY_LOCAL_MACHINE = &H80000002
'Predefined Registry Value Type
Const REG_SZ = (1) 'Unicode null terminated string
Public Function fCognosDate(dDate As String) As String
Public Function fOpenReport(sReportPath As String, _
sReport As String, _
sPromptValues As String, _
sExportMethod As String, _
sExportPath As String, _
sFileName As String)
On Error GoTo errMessage
Dim x As Variant
sReport = sReportPath & sReport
'Report
Set objImpApp = GetObject("CognosImpromptu.Application"
'Prompt Values
If sPromptValues = "" Then
Set objImpRep = objImpApp.OpenReport(sReport)
Else
Set objImpRep = objImpApp.OpenReport(sReport, sPromptValues)
End If
'objImpApp.Activate
objImpRep.RetrieveAll
'Checks the contents of the first row and column of the query data
On Error Resume Next 'To turn off error trapping
x = objImpRep.GetDataValue(1, 1)
On Error GoTo errMessage
'If Report contains info export
If IsEmpty(x) = False Then
'Export Report
Select Case sExportMethod
Case "Excel"
'Export To Excel
sFileName = sExportPath & sFileName & ".xls"
objImpRep.ExportExcel sFileName
Case "Pdf"
'Publish to PDF
Dim objPDFPub As Object
Set objPDFPub = objImpRep.PublishPDF
objPDFPub.Publish sExportPath & sFileName & ".pdf"
Set objPDFPub = Nothing
End Select
End If
'Close Report
'objImpRep.CloseReport
Set objImpRep = Nothing
Set objImpApp = Nothing
fOpenReport = True
Exit Function
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.