Thanks, here are the codes:
Option Explicit
Sub RefreshData()
'MsgBox “refresh data”
'On Error Resume Next
On Error GoTo ErrMsg
Open “\Capsbi.ocgov.com\pdf\test\BOError.log” For Output As #1
Dim Doc As Document
Set Doc = ActiveDocument
Dim Dir As String
'Save at local folder
'Dir = “C:\FTS_LaunchPad”
'save at Server using BCA
'Dir = “\Capsbi.ocgov.com\pdf” 'for release
Dir = “\Capsbi.ocgov.com\pdf\test” 'for testing only
'Define FileName
Dim docName As String
'docName = Doc.Name
Dim ds, ds1, ds2 As String
ds = Date
'MsgBox ds
Dim pos As Integer
pos = InStr(1, ds, “/”, 1)
'MsgBox pos
If pos > 0 Then
ds1 = Left(ds, pos - 1) & “-” & Right(ds, Len(ds) - pos)
Else
ds1 = ds
End If
'MsgBox ds1
pos = InStr(1, ds1, “/”, 1)
If pos > 0 Then
ds2 = Left(ds1, pos - 1) & “-” & Right(ds1, Len(ds1) - pos)
Else
ds2 = ds1
End If
'docName = “RevExpFBCashReport_” & ds2
docName = “FretQtrReport_” & ds2
’ MsgBox FileName
Dim FileName As String
'FileName = Dir & docName
Dim CheckPDFSize As Integer
'define Refresh
Dim FundCode() As String
Dim AgencyCode() As String
Dim NumDocs, startDocNo As Integer
Dim I As Integer
'Input data
’ # of documents to be produce – Need to be modifies
’
NumDocs = 7
'******************************************************
ReDim FundCode(NumDocs)
ReDim AgencyCode(NumDocs)
'starting document number – Need to be modified…
’
startDocNo = 4 'The last published report number
'**************************************************
'Need to modify the following array for given fund code
'and agency code
’
'CEO Funds
FundCode(1) = “289”
AgencyCode(1) = “289”
FundCode(2) = “291”
AgencyCode(2) = “291”
FundCode(3) = “292”
AgencyCode(3) = “292”
FundCode(4) = “293”
AgencyCode(4) = “293”
FundCode(5) = “294”
AgencyCode(5) = “294”
FundCode(6) = “295”
AgencyCode(6) = “295”
FundCode(7) = “298”
AgencyCode(7) = “298”
'FundCode(8) = “100”
'AgencyCode(8) = “003”
'FundCode(9) = “100”
'AgencyCode(9) = “060”
'FundCode(10) = “100”
'AgencyCode(10) = “074”
'FundCode(11) = “100”
'AgencyCode(11) = “080”
'FundCode(12) = “100”
'AgencyCode(12) = “047”
'FundCode(1) = “108”
'AgencyCode(1) = “108”
'FundCode(2) = “113”
'AgencyCode(2) = “113”
'Keep promts and othe boxes from shown up
busobj.Application.Interactive = False
ThisDocument.Application.BreakOnVBAError = False
For I = 1 To NumDocs
FileName = “”
FileName = Dir & docName
Doc.Variables.Item(1).Value = AgencyCode(I)
Doc.Variables.Item(2).Value = AgencyCode(I)
Doc.Variables.Item(3).Value = FundCode(I)
Doc.Variables.Item(4).Value = FundCode(I)
startDocNo = startDocNo + 1
'set up report number label
If (startDocNo < 10) Then
Doc.DocumentVariables.Item(“ReportNumber”).Formula = “00000” & startDocNo
ElseIf (startDocNo < 100) Then
Doc.DocumentVariables.Item(“ReportNumber”).Formula = “0000” & startDocNo
ElseIf (startDocNo < 1000) Then
Doc.DocumentVariables.Item(“ReportNumber”).Formula = “000” & startDocNo
ElseIf (startDocNo < 10000) Then
Doc.DocumentVariables.Item(“ReportNumber”).Formula = “00” & startDocNo
ElseIf (startDocNo < 100000) Then
Doc.DocumentVariables.Item(“ReportNumber”).Formula = “0” & startDocNo
Else
Doc.DocumentVariables.Item(“ReportNumber”).Formula = startDocNo
End If
Doc.Refresh
Doc.Save 'to update the date & time, 12/8/03
' Build file name
'
If StrComp(FundCode(I), AgencyCode(I), 1) = 0 Then
FileName = Trim(FileName) & "(" & Trim(FundCode(I)) & ")"
Else
FileName = Trim(FileName) & "(" & Trim(FundCode(I)) & "-" & Trim(AgencyCode(I)) & ")"
End If
Doc.ExportAsPDF (FileName)
'Check for files size, debugging only
'CheckPDFSize = FileLen(FileName)
'If CheckPDFSize > 0 Then
' MsgBox "ActiveDocument = " & FileName
'Else
' MsgBox "File Export Error - " & FileName
'End If
Next I
’ Reset the modes
Exit_Export_As_PDF:
busobj.Application.Interactive = True
ThisDocument.Application.BreakOnVBAError = True
'Set busobj = Nothing
’
Exit Sub
’
ErrMsg:
'Open “\Capsbi.ocgov.com\pdf\test\BOError.log” For Output As #1
Print #1, "Error: " & Err.Number & “-” & Err.Description
Close #1
’ reset the error and allows procedure to exit cleanly
Resume Exit_Export_As_PDF
End Sub
Note that if I ran it on an individual workstation, it’s OK. Only if I schedule it to run it using BCA, there are problems, such as that:
After few reports being generated the job got into loop for hours after failure…
Also, the error log file is empty.
The document itself consists a lot of calculations and is presented with 15 charts and their data tables. The data are drawn from 17 data providers. The document consists of 21 reports. I have timed it on my machine quite a few times for one single refresh. Normally it takes about 3-4 minutes for refresh and another 7-10 minutes for saving it as a PDF file.
Another problem I have been experiencing is the location of hyperlinks on the reports. After the document is converted into PDF format, the true hyperlink location will be either on the top of the url or below it. I need to move the url and footer ups and downs to make them on top of each other, a trial and error process that is VERY time-consuming. The true hyperlink positions are located randomly and can be anywhere on the report in PDF. I filed this problem to BO Technical Support Group last November, but no response whatsoever.
Again, thanks for all help and attention.
tyltyl (BOB member since 2003-03-28)