Nick Osdale-Popa
September 10th, 2003, 08:05 PM
Using Excel 97, I'm trying to open up some report files, applying a model, and then having Monarch display the Table view. After which, I want the macro to exit, leaving me in Monarch.
Monarch opens the files and model without problem, however, after that it gives me this error:
Monarch found a problem exporting the file
Automation error.
The server threw an exception.Not sure why it's giving me this error.
Here is the code I'm using:
Option Explicit
Global colFiles As Collection
Private ReportPath As String
Private ModelPath As String
Private objMonarch As Object
Private Const IsOn = 1
Private Const IsOff = 0
Private Const wdwMaximize = 0
Private Const wdwMinimize = 2
Function ProcessMonarch() As Boolean
On Error Resume Next
Set objMonarch = CreateObject("Monarch32")
On Error GoTo 0
If Err.Number <> 0 Then ProcessMonarch = False
OpenMonarch
End Function
Function OpenMonarch()
Const fOverwrite As Byte = 0
Const fNewTable As Byte = 1
Const fAppend As Byte = 2
Const ReportErr As Byte = 1
Const ModelErr As Byte = 2
Const TableErr As Byte = 3
Const NoSummaries As Byte = 4
Const SummaryErr As Byte = 5
Const sFirstView As String * 1 = "R"
Const DefaultFilter As String * 3 = "ALL"
Const WarningTitle As String * 46 = "Monarch Found a problem in Exporting The File."
Dim OpenFile As Boolean
Dim OpenModel As Boolean
Dim IsExported As Boolean
Dim SummaryCount As Integer
Dim SummaryIdx As Integer
Dim FilterCount As Integer
Dim Filter As Integer
Dim FileCount As Integer
Dim FileIdx As Integer
Dim sExportFile As String
Dim sProblem As String
Dim sReportFile As String
Dim sModelFile As String
Dim FilterName As String
Dim SummaryName As String
Dim FileExt As String
Dim strSheet As String
ReportPath = SOURCEDIR
ModelPath = MODELDIR
sModelFile = ModelPath & "" & ModelFile
On Error GoTo Monarch_Error
IsExported = True
With objMonarch
.Visible False
' .SetLogFile msExportPath & "" & "LOG.TXT", True
.SetFirstView (sFirstView)
'Open Report
If Not colFiles Is Nothing Then
.CloseAllDocuments
FileCount = colFiles.Count
For FileIdx = 1 To FileCount
sReportFile = colFiles(FileIdx)
sReportFile = ReportPath & "" & sReportFile
OpenFile = .SetReportFile(sReportFile, True)
'Raise Error if File Open failed
If OpenFile = False Then
IsExported = False
sProblem = "Error Opening File: " & sReportFile
Err.Raise vbObject + ReportErr, "Monarch", sProblem
End If
Next FileIdx
End If
'Raise Error if File Open failed
If OpenFile = False Then
IsExported = False
sProblem = "Error Opening File: " & sReportFile
Err.Raise vbObject + ReportErr, "Monarch", sProblem
End If
'Open Model
OpenModel = .SetModelFile(sModelFile)
'Raise Error if Model Open failed
If OpenModel = False Then
IsExported = False
sProblem = "Error with model: " & ModelFile
Err.Raise vbObject + ModelErr, "Monarch", sProblem
End If
.SetFirstView ("T")
End With
Exit_Open:
OpenMonarch = IsExported
Exit Function
Monarch_Error:
With objMonarch
.DisplayWindow (wdwMinimize)
.Visible = False
End With
Beep
MsgBox Err.Description, vbCritical, WarningTitle
Resume Exit_Open
End Function
Monarch opens the files and model without problem, however, after that it gives me this error:
Monarch found a problem exporting the file
Automation error.
The server threw an exception.Not sure why it's giving me this error.
Here is the code I'm using:
Option Explicit
Global colFiles As Collection
Private ReportPath As String
Private ModelPath As String
Private objMonarch As Object
Private Const IsOn = 1
Private Const IsOff = 0
Private Const wdwMaximize = 0
Private Const wdwMinimize = 2
Function ProcessMonarch() As Boolean
On Error Resume Next
Set objMonarch = CreateObject("Monarch32")
On Error GoTo 0
If Err.Number <> 0 Then ProcessMonarch = False
OpenMonarch
End Function
Function OpenMonarch()
Const fOverwrite As Byte = 0
Const fNewTable As Byte = 1
Const fAppend As Byte = 2
Const ReportErr As Byte = 1
Const ModelErr As Byte = 2
Const TableErr As Byte = 3
Const NoSummaries As Byte = 4
Const SummaryErr As Byte = 5
Const sFirstView As String * 1 = "R"
Const DefaultFilter As String * 3 = "ALL"
Const WarningTitle As String * 46 = "Monarch Found a problem in Exporting The File."
Dim OpenFile As Boolean
Dim OpenModel As Boolean
Dim IsExported As Boolean
Dim SummaryCount As Integer
Dim SummaryIdx As Integer
Dim FilterCount As Integer
Dim Filter As Integer
Dim FileCount As Integer
Dim FileIdx As Integer
Dim sExportFile As String
Dim sProblem As String
Dim sReportFile As String
Dim sModelFile As String
Dim FilterName As String
Dim SummaryName As String
Dim FileExt As String
Dim strSheet As String
ReportPath = SOURCEDIR
ModelPath = MODELDIR
sModelFile = ModelPath & "" & ModelFile
On Error GoTo Monarch_Error
IsExported = True
With objMonarch
.Visible False
' .SetLogFile msExportPath & "" & "LOG.TXT", True
.SetFirstView (sFirstView)
'Open Report
If Not colFiles Is Nothing Then
.CloseAllDocuments
FileCount = colFiles.Count
For FileIdx = 1 To FileCount
sReportFile = colFiles(FileIdx)
sReportFile = ReportPath & "" & sReportFile
OpenFile = .SetReportFile(sReportFile, True)
'Raise Error if File Open failed
If OpenFile = False Then
IsExported = False
sProblem = "Error Opening File: " & sReportFile
Err.Raise vbObject + ReportErr, "Monarch", sProblem
End If
Next FileIdx
End If
'Raise Error if File Open failed
If OpenFile = False Then
IsExported = False
sProblem = "Error Opening File: " & sReportFile
Err.Raise vbObject + ReportErr, "Monarch", sProblem
End If
'Open Model
OpenModel = .SetModelFile(sModelFile)
'Raise Error if Model Open failed
If OpenModel = False Then
IsExported = False
sProblem = "Error with model: " & ModelFile
Err.Raise vbObject + ModelErr, "Monarch", sProblem
End If
.SetFirstView ("T")
End With
Exit_Open:
OpenMonarch = IsExported
Exit Function
Monarch_Error:
With objMonarch
.DisplayWindow (wdwMinimize)
.Visible = False
End With
Beep
MsgBox Err.Description, vbCritical, WarningTitle
Resume Exit_Open
End Function