Word OLE VB sample is a simple Windows console application that converts a MS Word document (*C:\Test.doc*) to PDF using Word OLE automation. This sample demonstrates how to convert the existing Test.doc sample by printing it to novaPDF SDK Printer.
Note: To be able to use the samples you must install novaPDF SDK as samples work only with it. Download it here: nova PDF SDK.
Source Code
Attribute VB_Name = "Module1"
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
' the novapiLib and novapiLibDemo packages must be added as a COM reference
Const PRINTER_NAME As String = "novaPDF SDK 8"
Const PROFILE_NAME As String = "VB Word OLE"
Const PROFILE_IS_PUBLIC As Long = 0
' The main entry point for the application.
Public Sub Main()
On Error GoTo ErrorHandler:
' create the NovaPdfOptions object
Dim pNova As New NovaPdfOptions80
Dim sOldActiveProfileID As String
Dim sNewProfileID As String
' initialize the NovaPdfOptions object to use with a printer licensed for SDK
pNova.Initialize2 (PRINTER_NAME, "")
pNova.GetActiveProfile2 (sOldActiveProfileID)
' create new profile
On Error Resume Next
pNova.AddProfile2 PROFILE_NAME, PROFILE_IS_PUBLIC, sNewProfileID
pNova.LoadProfile2 (sNewProfileID)
' and set some options
pNova.SetOptionString2 NOVAPDF_DOCINFO_SUBJECT, "Test OLE document"
'save profile changes
pNova.SaveProfile
'set as active profile for printer
pNova.SetActiveProfile (sNewProfileID)
' set nova default printer
pNova.SetDefaultPrinter
' print word document
Dim objWord As Object
Dim objDoc As Object
pNova.InitializeOLEUsage "Word.Application"
Set objWord = CreateObject("Word.Application")
pNova.LicenseOLEServer
Set objDoc = objWord.Documents.Open("C:\Test.doc", False, True)
objDoc.PrintOut False
objDoc.Close False
objWord.Quit False
' restore default printer
pNova.RestoreDefaultPrinter
'restore default profile
If Len(sOldActiveProfileID) > 0 Then
pNova.SetActiveProfile2 (sOldActiveProfileID)
End If
'delete newly created profile
pNova.DeleteProfile2 (sNewProfileID)
Exit Sub
ErrorHandler:
Debug.Print Err.Number & ":" & Err.Description
End Sub