Computer Hope

Microsoft => Microsoft Windows => Windows XP => Topic started by: Striver on July 06, 2006, 07:20:09 AM

Title: Macro in Word
Post by: Striver on July 06, 2006, 07:20:09 AM
Hi,

I'm trying to write a macro in a Word document (Testdoc.doc) that will print the file Testdoc.doc to a pdf file. This is the function (in Visual Basic) in the macro that does that:

Public Sub bd2pdf_print(Printer As String, FilePath As String, OutputFile As String)
  
  ActivePrinter = Printer

  Application.PrintOut FileName:=FilePath, Range:=wdPrintAllDocument, Item:= _
        wdPrintDocumentContent, Copies:=1, Pages:="1", PageType:=wdPrintAllPages, _
        Collate:=True, Background:=False, PrintToFile:=True, OutputFileName:=OutputFile, _
        Append:=False

End Sub

Public Sub bd2pdf_close()
 ActiveDocument.Close wdDoNotSaveChanges
End Sub

The parameters "Printer, FilePath, OutputFile" are submitted by a Visual Basic program that I have.
So in that program, I open the word document and then use the command: docapp.Run "bd2pdf_close" (where docapp is Word application) to run the macro. I actually manage to generate a pdf file, but there is something wrong with it. So I wonder if maybe this is correct what I do?
Grateful for help!
Title: Re: Macro in Word
Post by: Rob Pomeroy on July 07, 2006, 03:41:57 AM
Quote
I actually manage to generate a pdf file, but there is something wrong with it.
What exactly is wrong with it?

Is there a particular reason why you need to do this programatically?  You could install PrimoPDF and use that to generate the PDF...?