Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WORD PRINT LAST PAGE - AMEND WORKING SCRIPT

Status
Not open for further replies.

luke99re

Technical User
Dec 6, 2013
1
GB
Hi,

I have this working vbs script that currently prints all files and all pages in a folder with a specific file extension.
I need to add a line that will for each opened document, move to the end of the document and prints just the last page.

so, how can I just print the last page of all the files. the problem is that each file may have different number of pages.

I tried bookmark end of document, goto last page, etc but not quite achieving, please advice. thank you.

see the bold section, thanks.

'--------------------------------------------------------------------
'Print All XML documents using WORD
'--------------------------------------------------------------------

Dim objFSO, objShell
Dim objWord, docWord

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")

'Set objShell = CreateObject ("Shell.Application")
'Set objFolder = objShell.Namespace ("M:\IMSU\PrintFolder")

' GET the current path of the script
strPath = Wscript.ScriptFullName
Set objFile = objFSO.GetFile(strPath)
strFolder = objFSO.GetParentFolderName(objFile)

ext = InputBox("Enter the file extention (without the dot): ")
ext = ucase(ext)


' Prompt and make sure
ccode = MsgBox("Print all " & ext & "files from folder" & vbCRLF & "[" & strfolder & "]" & vbCRLF & vbCRLF & "Are you sure?", 4)


If ccode <> vbYES Then wscript.quit

Set folder = objFSO.GetFolder(strFolder)

Set objWord = CreateObject("Word.Application")
objWord.Visible = True

For Each file in folder.Files
'wscript.echo file.Name
If right(ucase(file.Name),len(ext)) = ext Then
Set docWord = objWord.Documents.Open(strFolder & "\" & file.Name)
objWord.ActiveDocument.Printout
objWord.ActiveDocument.Saved = True
objWord.ActiveDocument.Closee
End If
Next

ObjWord.Quit

 
try:
Code:
With objWord.ActiveDocument
  .PrintOut Pages:=.ComputeStatistics(2) '2 = wdStatisticPages
  .Saved = True
  .Close
End With

Cheers
Paul Edstein
[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top