The Task: Insert A4 images into a word document and print them using OLE and VB. The code was created by recording macros and modifying the VBA code.
The print jobs go into the queue, but the server reports "Print job deleted" in it's event log. This does not happen if I use .SaveAs instead of PrintOut and manually print the document.
Mostly the print job is deleted, sometimes it prints out the first couple of inches of the page.
Any Clues?
THE CODE
------------
The print jobs go into the queue, but the server reports "Print job deleted" in it's event log. This does not happen if I use .SaveAs instead of PrintOut and manually print the document.
Mostly the print job is deleted, sometimes it prints out the first couple of inches of the page.
Any Clues?
THE CODE
------------
Code:
If oWordApp Is Nothing Then
Set oWordApp = CreateObject("Word.Application")
End If
oWordApp.WindowState = 2 ' wdWindowStateMinimize
oWordApp.Visible = True
oWordApp.Documents.Add DocumentType:=0 'wdNewBlankDocument
Set oNewDoc = oWordApp.ActiveDocument
strFileName = oSI.fn_ScanImage_GetPath
Call gflFreeFileInformation(gflFileInfo)
eRet = gflGetFileInformation(strFileName, -1, gflFileInfo)
If eRet <> GFL_NO_ERROR Then
Err.Raise vbObjectError + eRet, "GFL SDK", extGetStr _
(gflGetErrorString(eRet))
End If
With oNewDoc.PageSetup
If gflFileInfo.Width > gflFileInfo.Height Then
.orientation = 1 'wdOrientLandscape
Else
.orientation = 0 'wdOrientPortrait
End If
.TopMargin = 0 'oWordApp.CentimetersToPoints(3)
.BottomMargin = 0 'oWordApp.CentimetersToPoints(3)
.LeftMargin = 0 'oWordApp.CentimetersToPoints(3)
.RightMargin = 0 'oWordApp.CentimetersToPoints(3)
End With
oNewDoc.Shapes.AddPicture(strFileName, False, _
True, , , , ,oWordApp.Selection.Range)_
.WrapFormat.Type = 4 'wdWrapTopBottom
blnOK = oSI.fn_ScanImage_RecordsetMove(enMoveNext, True, _
oConn, strErrMsg)
Do Until oSI.fn_ScanImage_RecordsetEOF Or Not blnOK
strFileName = oSI.fn_ScanImage_GetPath
Call gflFreeFileInformation(gflFileInfo)
eRet = gflGetFileInformation(strFileName, -1, gflFileInfo)
If eRet <> GFL_NO_ERROR Then
Err.Raise vbObjectError + eRet, "GFL SDK", extGetStr _
(gflGetErrorString(eRet))
End If
oWordApp.Selection.EndKey Unit:=6 'wdStory
oWordApp.Selection.InsertBreak _
Type:=2 'wdSectionBreakNextPage
With oWordApp.Selection.PageSetup
If gflFileInfo.Width > gflFileInfo.Height Then
.orientation = 1 'wdOrientLandscape
Else
.orientation = 0 'wdOrientPortrait
End If
.TopMargin = 0
.BottomMargin = 0
.LeftMargin = 0
.RightMargin = 0
.SectionStart = 2 'wdSectionNewPage
End With
oNewDoc.Shapes.AddPicture(strFileName, False, _
True, , , , , oWordApp.Selection.Range) _
.WrapFormat.Type = 4 'wdWrapTopBottom
blnOK = oSI.fn_ScanImage_RecordsetMove(enMoveNext, _
True, oConn, strErrMsg)
Loop
oNewDoc.PrintOut Range:=0, Item:= 0, Copies:=1, Pages:="", _
PageType:=0, ManualDuplexPrint:=False, _
Collate:=True, Background:=True, _
PrintToFile:= False, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
oNewDoc.Close False
Set oNewDoc = Nothing
oWordApp.Quit
Set oWordApp = Nothing