Results 1 to 8 of 8
  1. #1
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Force PrintLayout view (WinXP / Word2003 NL)

    In a Sub I open a new document based on a specific template with:

    Dim TargetDoc As Word.Document
    Set TargetDoc = Documents.Add(Template:="T:WordTemplatesRequest.do t")
    '
    ' some more code
    '
    TargetDoc.ActiveWindow.View.Type = wdPrintView
    TargetDoc.SaveAs FileName:="C:TestRequest.doc"
    TargetDoc.Close

    The problem is that, to my surprise, after opening Request.doc is shown in Normal view, despite of the first line with View.Type above. Manually applying View | PrintView and then saving & closing again seems to cure the problem: re-opening shows the doc in Printview. Can anyone shed some light at this?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Force PrintLayout view (WinXP / Word2003 NL)

    I cannot reproduce this, but you could set Print View in the Document_Open event of the Request.dot template:

    Private Sub Document_Open()
    ActiveWindow.View = wdPrintView
    End Sub

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Force PrintLayout view (WinXP / Word2003 NL)

    Word stores the view only if it considers the document to be dirty (unsaved) when closing. For instance if I open a file and do nothing to it other than change the view then this won't be saved but if I change the view and also add a character to the file then the view will be saved on next open.

    I think you would have more luck if you changed the view, then did something 'saveworthy' such as a text change (and unchange if you like) and then saved the document.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Force PrintLayout view (WinXP / Word2003 NL)

    Thanks Hans, but I cannot do that. All our templates are code-less and have to stay that way. All code sits in a global code-only template.

  5. #5
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Force PrintLayout view (WinXP / Word2003 NL)

    Thanks Andrew. I know that Word only saves documents that are "dirty". And the TargetDoc in my original post must be "dirty" because it is just created and not saved yet. It's the result of converting a document that in reality is a disguised remplate - see my <post:=518,370>post 518,370</post:>.
    The whole conversion code (typed over, cannot upload anything because I'm not on my own work-PC right now, so typo's may occur):
    <font face="Georgia">
    Sub ConvertDoc
    Dim SourceDoc As Word.Document
    Dim TargetDoc As Word.Document
    Dim rngSourceDoc As Range
    Dim rngTargetDoc As Range
    Dim strConvDoc As String
    Dim strTemplate As String
    Dim strTemplPath as String

    On Error Goto Error_ConvertDoc

    Application.ScreenUpdating = False
    System.Cursor = wdCursorWait

    Set SourceDoc = ActiveDocument
    strConvDoc = SourceDoc.FullName
    strTemplate = LCase(SourceDoc.CustomDocumentProperties("Template ").Value) & ".doc"
    strTemplPath = "T:WordTemplates"
    Set TargetDoc = Documents.Add(Template:=strTemplPath & strTemplate, Visible:=False)

    SourceDoc.Activate
    ProtOff SourceDoc 'Generic Sub to lift document protection
    Set rngSourceDoc = SourceDoc.Range
    rngSourceDoc.MoveEnd Count:=-1
    rngSourceDoc.Copy

    TargetDoc.Activate
    ProtOff TargetDoc
    TargetDoc.Content.Delete
    TargetDoc.Range.Paste
    ProtOn TargetDoc 'Generic Sub to set document protection

    TargetDoc.ActiveWindow.View.Type = wdPrintView
    TargetDoc.ActiveWindow.Visible = True
    SourceDoc.Close SaveChanges:=wdDoNotSaveChanges
    Kill strConvDoc
    TargetDoc.SaveAs FileName:=strConvDoc

    Exit_Error:
    If Not TargetDoc Is Nothing Then TargetDoc.Close SaveChanges:=wdDoNotSaveChanges
    System.Cursor = wdCursorNormal
    Application.ScreenUpdating = True
    Set SourceDoc = Nothing
    Set TargetDoc = Nothing
    Set rngSourceDoc = Nothing
    Set rngTargetDoc = Nothing
    Exit Sub

    Error_ConvertDoc:
    Select Case Err.Number
    Case 4605
    Err.Clear
    Resume Next 'No Paste
    Case Else
    MsgBox "Error nr.:"& vbTab & Err.Number & vbLf & _
    "Descr.:"& vbTab & Err.Description, _
    vbCritical + vbOKOnly, "iBox: ConvertDoc"
    Resume Exit_Error
    End Select
    End Sub
    </font face=georgia>
    So this conversion is a copy of the whole content of a template-doc into a new, real doc based on the same template. That's why I don't understand why PrintView doesn't stick. Apart from this, the conversion works as intended, but any comments and suggestions about this piece of code are welcome.

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Force PrintLayout view (WinXP / Word2003 NL)

    Perhaps SaveAs doesn't save the view but Save does?

    Another possibility is that the ProtOn function actually saves the document and then the SaveAs saves a non-dirty file.

    Does the macro get noticeably slowed down if you move the PrintView line above the Paste line (two lines above)?
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Force PrintLayout view (WinXP / Word2003 NL)

    THe following works in Word 2003, whether or not I use the With construct.
    <pre> Dim TargetDoc As Word.Document
    Set TargetDoc = Documents.Add(Template:=NormalTemplate.FullName)
    '
    ' some more code
    '
    With TargetDoc
    .ActiveWindow.View.Type = wdPrintView
    .SaveAs FileName:="C:TestRequest.doc"
    .Close
    End With
    </pre>


    Are you certain that there are no AutoClose or document_close subs lurking?

  8. #8
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Force PrintLayout view (WinXP / Word2003 NL)

    Thanks Andrew and Howard.

    The ProtOn / ProtOff functions do just that: set or lift the protection of a document. I made those functions myself, so I'm positiv that there's no Save in them.
    Moving the PrintView line doesn't slow the macro down, but it didn't do the trick either. But I solved the problem by adding a paragraph at the end of the docs after the initial Save As and then Saving the doc again. So you were right in your first reply, Andrew, about only saving the altered View when something else is changed. Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •