我遇到ActiveX组件的问题,无法创建对象错误。奇怪的是文件工作到今天都非常好。按下“确定”按钮后,表单会向用户显示将表单打印为PDF的选项。我在Set oWord = CreateObject(" Word.Application")上收到错误。任何想法我可能做错了什么?
Dim fileOK As Boolean
Dim sPrinter As String
With Application
sPrinter = .ActivePrinter
fileOK = .Dialogs(xlDialogPrinterSetup).Show
End With
If fileOK = True Then
ChangeDefaultPrinter (Application.ActivePrinter)
UserForm.PrintForm
ChangeDefaultPrinter (sPrinter)
End If
Unload UserForm
End Sub
Public Sub ChangeDefaultPrinter(pName As String)
Set oWord = CreateObject("Word.Application")
oWord.WordBasic.FilePrintSetup Printer:=pName, DoNotSetAsSysDefault:=0
Set oWord = Nothing
End Sub