Use Automation to set View.Type = wdPrintView

K

kiln

I've scoured around a bit and couldn't find a snippet that would allow
me to set a collection of word 2000 docs to Print Layout view
programatically.

ActiveWindow.View.Type = wdPrintView

seems to do the trick if the doc is open; but I'm doing this from
outside of word to hundreds of docs. Hoping someone can give me a
pointer here, thanks.
 
J

Jay Freedman

Hi kiln,

There's no way to change the saved view of a document without opening
it in Word, at least not by using VBA or automation. You have to open
each document, change its view, do something to make Word think the
file needs to be saved (changing the view doesn't "dirty" the
document), and save and close it. The code to do that to all the files
in a single folder is this:

Sub SetViewInDocs()
Dim oDoc As Document
Dim strFN As String

' change the path as needed
' keep the final backslash
Const strPath = "C:\Temp\"

strFN = Dir$(strPath & "*.doc")
Do While strFN <> ""
Set oDoc = Documents.Open(strPath & strFN)

' change the view
ActiveWindow.View.Type = wdPrintView

' make Word think there's something to save
oDoc.Saved = False

oDoc.Close SaveChanges:=wdSaveChanges

strFN = Dir$()
Loop
End Sub
 
K

kiln

Thanks Jay, I was sort of guessing that this might be the case; hoping
against, but anyways, it'll work. Your code is an assist, thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top