Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-14-2013, 03:10 PM
kar64 kar64 is offline vba word 2003: printout prints only the first page of the file Windows 7 64bit vba word 2003: printout prints only the first page of the file Office 2003
Novice
vba word 2003: printout prints only the first page of the file
 
Join Date: Feb 2013
Posts: 2
kar64 is on a distinguished road
Default vba word 2003: printout prints only the first page of the file

Hi all.
I'm Italian. Sorry for my bad English.
First: I do not know to program in vba word and write what I derived from the macro recorder and the Internet.



In my code I open a doc file, edit the footer and print the document.
I do it with this code:

Code:
nomefiletab = (Trim(Testo99.Value & "")) + "\" + Right("000" + Trim(CasellaCombinata34 & ""), 3) + "_test.DOC" 
If FileEsiste3(nomefiletab) Then 
    For nco = 1 To Val(tabst2co) 
        piepag = "" 
        piepag = "TEST - Allegato " & trim(str(nco)) 
            Set objWord = New Word.Application 
            Set wDoc = objWord.Documents.Open(nomefiletab) 

            ' cancella il pie' di pagina vecchio 
            objWord.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter 
            objWord.Selection.ParagraphFormat.Alignment = wdAlignParagraphRight 
            objWord.Selection.Delete Unit:=wdCharacter, Count:=1 
            objWord.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter 
            objWord.Selection.EndKey Unit:=wdLine, Extend:=wdExtend 
            objWord.Selection.Delete Unit:=wdCharacter, Count:=1 
            objWord.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 
     
            ' aggiunge il pie' di pagina nuovo 
            objWord.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter 
            objWord.Selection.ParagraphFormat.Alignment = wdAlignParagraphRight 
            objWord.Selection.Font.Name = "Courier New" 
            objWord.Selection.Font.Size = 7 
            objWord.Selection.Font.Bold = True 
            objWord.Selection.TypeText Text:=piepag 
            objWord.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 
    
'            objWord.ActiveDocument.ActiveWindow.Activate 
            objWord.Application.WindowState = wdWindowStateMinimize 
            wDoc.Activate 
  
            objWord.Visible = True 
            
            'objWord.ActiveDocument.PrintPreview 
         
            ' stampa il documento 
            wDoc.PrintOut 
   
            wDoc.Close 
            objWord.Quit SaveChanges:=wdDoNotSaveChanges 
             
            Set objWord = Nothing 
            Set wDoc = Nothing 
             
    Next nco 
    S2OK.Visible = True 
     
endif
Well if I go to print preview ('objWord.ActiveDocument.PrintPreview) everything works, if I use printout print the first page of the document!

I do not know how to solve.

Someone can 'help me?

thanks
Reply With Quote
  #2  
Old 02-14-2013, 08:36 PM
macropod's Avatar
macropod macropod is offline vba word 2003: printout prints only the first page of the file Windows 7 64bit vba word 2003: printout prints only the first page of the file Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi kar64,

Try the following - it should be much more efficient:
Code:
Dim objWord As Word.Application
Dim wDoc As Word.Document
nomefiletab = Trim(Testo99.Value) & "\" & Right("000" + Trim(CasellaCombinata34), 3) & "_test.DOC"
If Dir(nomefiletab) <> "" Then
    Set objWord = New Word.Application
    objWord.Visible = True
    For nco = 1 To Val(tabst2co)
        piepag = "TEST - Allegato " & Trim(CStr(nco))
        Set wDoc = objWord.Documents.Open(nomefiletab, AddToRecentFiles:=False)
        With wDoc
            With .Sections.First.Footers(wdHeaderFooterPrimary).Range
                'cancella il pie' di pagina vecchio & aggiunge il pie' di pagina nuovo
                .Text = piepag
                .ParagraphFormat.Alignment = wdAlignParagraphRight
                With .Font
                    .Name = "Courier New"
                    .Size = 7
                    .Bold = True
                End With
            End With
            ' stampa il documento
            .PrintOut Range:=wdPrintAllDocument
            .Close SaveChanges:=wdDoNotSaveChanges
        End With
    Next nco
    objWord.Quit
    Set wDoc = Nothing: Set objWord = Nothing
    S2OK.Visible = True
End If
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-15-2013, 02:42 PM
kar64 kar64 is offline vba word 2003: printout prints only the first page of the file Windows 7 64bit vba word 2003: printout prints only the first page of the file Office 2003
Novice
vba word 2003: printout prints only the first page of the file
 
Join Date: Feb 2013
Posts: 2
kar64 is on a distinguished road
Default

I modified as you suggested. Okay. thanks
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
vba word 2003: printout prints only the first page of the file embed autocad drawing in word document prints very light gbehm@broan.com Drawing and Graphics 1 03-15-2011 08:05 PM
Extaneous Unwanted file information prints junehorner Word 2 01-23-2011 12:27 PM
Printout problem with customized bullets eroock PowerPoint 2 12-27-2009 02:11 PM
word only prints pictures AidyTy Word 0 12-15-2009 01:50 PM
Footer so low on page only top half prints Renee Hendershott Word 1 01-22-2006 05:09 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:26 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft