Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Sep 2003
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Printed Copies (VB6 Word XP)

    When ever my VB6 program prints a word document after revising the number of copies is always 1 higher than the specified number. If I select 2 copies in my program's printer dialog box putting 2 in the global NumberOfCopies variable I get 3 copies out of my HP LaserJet III. My code is as follows:

    Sub PrintInstructions(InstructionFile As String, DateDue As String, _
    Optional AmountDue As String)

    'define variables
    Dim objWordApp As Object

    'create objects
    Set objWordApp = CreateObject("Word.Application")

    'format amountdue to have thousands seperator
    AmountDue = Format(AmountDue, "##,##0.00")

    'format datedue to be in the month name, day # year format
    DateDue = Format(DateDue, "mmmm, d yyyy")

    'opens an existing word docuement
    objWordApp.Documents.Open (InstructionFile)

    'selects all text
    objWordApp.Selection.Find.ClearFormatting
    objWordApp.Selection.Find.Replacement.ClearFormatt ing
    With objWordApp.Selection.Find
    .Text = "DATEDUE" ' word to search for
    .Replacement.Text = DateDue ' word to replace with
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = True
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    objWordApp.Selection.Find.Execute Replace:=wdReplaceAll 'Do all the replacing now

    If AmountDue <> "" Then
    'selects all text
    objWordApp.Selection.Find.ClearFormatting
    objWordApp.Selection.Find.Replacement.ClearFormatt ing
    With objWordApp.Selection.Find
    .Text = "AMOUNTDUE" ' word to search for
    .Replacement.Text = AmountDue ' word to replace with
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = True
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    objWordApp.Selection.Find.Execute Replace:=wdReplaceAll 'Do all the replacing now
    End If

    'save default printer
    DefaultPrinter = PF.GetCurrPrinter(PF.GetOS)

    'print doucment
    objWordApp.ActiveDocument.Saved = True
    objWordApp.ActivePrinter = SelectedPrinter
    objWordApp.PrintOut False, NumberOfCopies
    objWordApp.ActiveDocument.PrintOut

    'restore default printer
    objWordApp.ActivePrinter = DefaultPrinter

    'close document
    objWordApp.ActiveDocument.Saved = True
    objWordApp.ActiveDocument.Close

    'close word
    objWordApp.Quit

    'destroy objects
    Set objWordApp = Nothing
    End Sub

    All variables not defined in this sub routine are declared with dim statements in the (General) (Declarations) section.

    PF is defined with Dim PF As New clsPrinterFunctions in the (General) (Declarations) section.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Printed Copies (VB6 Word XP)

    You have two print instructions in your code:

    objWordApp.PrintOut False, NumberOfCopies
    objWordApp.ActiveDocument.PrintOut

    The first instruction will print the selected number of copies, then the second instruction will print one more, or am I completely off?

  3. #3
    New Lounger
    Join Date
    Sep 2003
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printed Copies (VB6 Word XP)

    That was it. I was experimenting with different lines of code when I was determing how users would select a printer for the word doc and the PDF file (printed via different sub routine) and forgot to take out the test one.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •