Solved

VBSCRIPT that opens a RTF file in word PRINT PREVIEW mode and saves it in another folder

Posted on 2013-01-25
3
813 Views
Last Modified: 2013-02-04
Hello EE,

I have several rtf files that were created using SAS.  The page numbers (Page x of y) "appear" to be missing but can be seen if opened in "Print Preview" or when the table is printed.  What I would like to do is run a vbscript that does the following:  1) opens the file in "Print Preview (CTRL+F2)" mode.  2) file "save as" the same file in another folder.  This saved file will now show  the page numbers.  I currently have about 100 files and I really don't want to do this to each one.  I am attaching the file as an example.  This script will then be used as the second step of the process to see the page number values.  

Thanks in advance for your help...

Jeff
LBI-PTRB3SCR-smdisd1-test.doc
0
Comment
Question by:ratliffjm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

Assisted Solution

by:Robert Schutt
Robert Schutt earned 500 total points
ID: 38825029
Try this:
Option Explicit

Const C_FOLDER_BASE = "C:\temp\"

Const C_FOLDER_INP = "input\"
Const C_FOLDER_OUT = "output\"

Const wdFormatDocument = 0

Dim oWrdApp, oWrdFil, oFS, oFolderInp, oFile, oFolderOut

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

Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFolderInp = oFS.GetFolder(C_FOLDER_BASE & C_FOLDER_INP)

For Each oFile In oFolderInp.Files
    If LCase(Right(oFile.Name, 4)) = ".rtf" Then
        Set oWrdFil = oWrdApp.Documents.Open(oFile.Path, False, False, False)
        oWrdFil.PrintPreview
        oWrdFil.SaveAs C_FOLDER_BASE & C_FOLDER_OUT & Left(oFile.Name, Len(oFile.Name) - 3) & "doc", wdFormatDocument, , , False
        oWrdFil.Close False
        Set oWrdFil = Nothing
    End If
Next

Set oFolderInp = Nothing
Set oFS = Nothing

oWrdApp.Quit
Set oWrdApp = Nothing

Open in new window

0
 

Author Comment

by:ratliffjm
ID: 38832197
I edited your code and I got the following error:

Script" S:\REFMAL197\pageit.vbs
Line:16
Char: 1
Error: Path not found
Code: 800A004C
Source: Microsoft VBScript runtime error

My edited code is below. I think I made a mistake with the C_FOLDER_BASE. What should be the path of this value?

Option Explicit

Const C_FOLDER_BASE = "S:\REFMAL197\Deliverable\TFL\Production\Output\output_test\"

Const C_FOLDER_INP = "S:\REFMAL197\Deliverable\TFL\Production\Output\output_test\"
Const C_FOLDER_OUT = "S:\REFMAL197\Deliverable\TFL\Production\Output\output_testit\"

Const wdFormatDocument = 0

Dim oWrdApp, oWrdFil, oFS, oFolderInp, oFile, oFolderOut

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

Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFolderInp = oFS.GetFolder(C_FOLDER_BASE & C_FOLDER_INP)

For Each oFile In oFolderInp.Files
    If LCase(Right(oFile.Name, 4)) = ".rtf" Then
        Set oWrdFil = oWrdApp.Documents.Open(oFile.Path, False, False, False)
        oWrdFil.PrintPreview
        oWrdFil.SaveAs C_FOLDER_BASE & C_FOLDER_OUT & Left(oFile.Name, Len(oFile.Name) - 3) & "doc", wdFormatDocument, , , False
        oWrdFil.Close False
        Set oWrdFil = Nothing
    End If
Next

Set oFolderInp = Nothing
Set oFS = Nothing

oWrdApp.Quit
Set oWrdApp = Nothing



Thanks  so much!!!

Jeff
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 38834244
The intentention was to use BASE as the base folder and input and output below it:
Const C_FOLDER_BASE = "S:\REFMAL197\Deliverable\TFL\Production\Output\"

Const C_FOLDER_INP = "output_test\"
Const C_FOLDER_OUT = "output_testit\"

Open in new window

This would mean the files are currently in output_test. If not, just leave the input folder empty.
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question