How can I prevent implicit view changes?

M

moritz

I'm inserting page elements using macros. Whenever I use the PageSetup
object, the current view changes to the print view and the open task pane
disappears as a side effect.

Am I causing this or is this expected behavior?

How can I prevent this behavior?

Or alternatively, how can I restore the settings prior to the macro
invocation - particularly the closed task pane?

Thanks for any feedback.

Regards,

Andreas
 
C

Cindy M.

Hi =?Utf-8?B?bW9yaXR6?=,
I'm inserting page elements using macros. Whenever I use the PageSetup
object, the current view changes to the print view and the open task pane
disappears as a side effect.

Am I causing this or is this expected behavior?

How can I prevent this behavior?

Or alternatively, how can I restore the settings prior to the macro
invocation - particularly the closed task pane?
Please show use the code in question. Which version of Word?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
M

moritz

Cindy,

Thanks for responding. I've extracted the relevant parts into the macro
below. To reproduce, change into the normal view, apply the macro, and Word
2003 SP2 will have switched to the print view after its execution. Please
note that the task pane doesn't disappear anymore - I have to investigate
what had caused this to occur.

Regards,

Andreas

Sub InsertFormatting()
Application.ScreenUpdating = False
Selection.InsertBreak Type:=wdSectionBreakContinuous
With Selection.PageSetup.TextColumns
.SetCount NumColumns:=2
.EvenlySpaced = False
.LineBetween = False
End With

Selection.TypeParagraph
Selection.Style = ActiveDocument.Styles("Normal")
Selection.InsertBreak Type:=wdColumnBreak

Selection.TypeParagraph
Selection.Style = ActiveDocument.Styles("Normal")
Selection.MoveRight Unit:=wdCharacter, Count:=1

With Selection.PageSetup.TextColumns(2)
.Width = InchesToPoints(1.83)
End With
With Selection.PageSetup.TextColumns(1)
.Width = InchesToPoints(3.67)
.SpaceAfter = InchesToPoints(0.5)
End With
Selection.InsertBreak Type:=wdSectionBreakContinuous
With Selection.PageSetup.TextColumns
.SetCount NumColumns:=1
.EvenlySpaced = False
.LineBetween = False
End With
Selection.InsertBreak Type:=wdPageBreak

Application.ScreenUpdating = False
End Sub
 
C

Cindy M.

Hi =?Utf-8?B?bW9yaXR6?=,
I've extracted the relevant parts into the macro
below. To reproduce, change into the normal view, apply the macro, and Word
2003 SP2 will have switched to the print view after its execution.
Ah, seeing the code, I can tell you what's causing the shift to Print View:
setting the number of columns. Columns can be laid out correctly only in the
Print View; Normal view doesn't display newspaper columns as columns, so when
the user adds columns, Word switches. Since you're using the Selection object,
Word behaves as it would if you were a user. But if you were to work with the
RANGE instead of the SELECTION object the view won't switch:

Dim rng As Word.Range

Application.ScreenUpdating = False
Set rng = Selection.Range
rng.InsertBreak Type:=wdSectionBreakContinuous
With rng.PageSetup.TextColumns
.SetCount NumColumns:=2
.EvenlySpaced = False
.LineBetween = False
End With

You need to learn how to use Range instead of selection for your code. At
first, you'll find it confusing because a range contains everything you assign
to it (think in terms of the selection extending). After you assing text to a
range and you need to do something else with it, you'll want to use the
Collapse method to reduce it to a single "point" (think blinking cursor)
before assigning more text.

You'll need to do a bit of experimenting to get a feel for this :)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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