Dinakar Nethi

A .NET/SQL Server Blog

<January 2009>
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567


Navigation

About Me

Links

Subscriptions

Article Categories



Automatically print html pages from a folder

This article describes how to go through a bunch of HTML files in a folder and  open each HTML file in a word document and print it.

-----------------------------------------------------------------------------

Sub PrintPages()

 Dim path As String
 Dim word_Server As Word.Application
 Dim d() As String

 path = "C:\Inetpub\wwwroot\newDir\" ' set the path
 word_Server = New Word.Application()
 
 With word_Server
  .ChangeFileOpenDirectory(path)
 End With

 d = System.IO.Directory.GetFiles(path)
 Dim en As System.Collections.IEnumerator
 en = d.GetEnumerator
 While en.MoveNext

word_Server.Documents.Open(_
   filename:=CStr(en.Current),_
   ConfirmConversions:=False,_
   ReadOnly:=False, _
   AddToRecentFiles:=False,_
   PasswordDocument:="",_
   PasswordTemplate:="",_
   Revert:=False,_
   WritePasswordDocument:="",_
   WritePasswordTemplate:="",_
   Format:=Word.WdOpenFormat.wdOpenFormatAuto)

word_Server.Application.PrintOut( _
   filename:=CStr(en.Current), _
   Range:=Word.WdPrintOutRange.wdPrintAllDocument, _
   Item:= Word.WdPrintOutItem.wdPrintDocumentContent, _
   Copies:=1, _
   Pages:="", _
   PageType:=Word.WdPrintOutPages.wdPrintAllPages, _
   ManualDuplexPrint:=False, _
   Collate:=True, _
   Background:=True, _
   PrintToFile:= False, _
   PrintZoomColumn:=0, _
   PrintZoomRow:=0, _
   PrintZoomPaperWidth:=0, _
   PrintZoomPaperHeight:=0)

 End While

 CType(word_Server, Word.ApplicationClass).Quit()

 word_Server = Nothing

End Sub

posted on Friday, June 11, 2004 2:38 PM by dinakar





Powered by Dot Net Junkies, by Telligent Systems