![]() |
#1
|
|||
|
|||
![]() 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 I do not know how to solve. Someone can 'help me? thanks |
#2
|
||||
|
||||
![]()
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] |
#3
|
|||
|
|||
![]()
I modified as you suggested. Okay. thanks
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
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 |