Results 1 to 11 of 11
  1. #1
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Screen Updating (VBA/Word/2000)

    I am trying to control screen updating without much success.
    I am using:
    Application.ScreenUpdating = False
    However, I think my problem comes from this line:
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    But I can't think of a better way to get into the header.
    My goal here is to get into the header, create a range, type some text and then go to the footer for something similar.

    Any suggestions?

    Cheers
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  2. #2
    Lounger
    Join Date
    Aug 2001
    Location
    Perth,(aka middle of nowhere), Western Australia, Australia
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Screen Updating (VBA/Word/2000)

    My code for this is essentially the same and it works fine.
    Do you have a 'With' clause above the ActiveWindow
    I am using Selection rather than Range and include the document i.e.

    Set NewDoc = Documents.Add
    With NewDoc
    With .ActiveWindow ' set up the header & footer
    .Selection.HomeKey Unit:=wdStory ' Go to the top of the document
    .View.Type = wdPageView ' Go to page view
    .ActivePane.View.SeekView = wdSeekCurrentPageFooter
    NormalTemplate.AutoTextEntries("Page X of Y").Insert Where:=Selection.Range
    Selection.TypeText Text:=" "
    NormalTemplate.AutoTextEntries("Created on").Insert Where:=Selection.Range
    .ActivePane.View.SeekView = wdSeekCurrentPageHeader
    Selection.TypeText Text:="Result of Scan of " & SourceDoc
    ...
    etc


    Hope this helps

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Screen Updating (VBA/Word/2000)

    I have used this method successfully; the header and footer are never visible on the screen. Beware, however: anything in the footer gets wiped out because I am not collapsing the range to the end before inserting the page number field (which I didn't know how to do when I wrote this, and maybe I don't really know how yet).

    With doc2 'that's a document object, BTW
    .Activate
    .Sections(1).Headers(wdHeaderFooterPrimary).Range. InsertAfter "WorldMail Configuration as of " & Format(Date, "MMMM d, yyyy")
    .Fields.Add .Sections(1).Footers(wdHeaderFooterPrimary).Range, wdFieldPage
    With .Sections(1).Footers(wdHeaderFooterPrimary).Range
    .InsertBefore "Page "
    .Paragraphs(1).Alignment = wdAlignParagraphCenter
    End With
    End With

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Screen Updating (VBA/Word/2000)

    Jefferson's method gives an example of how to get stuff to the header/footer without needing to actually go to into the header/footer, by addressing a range.

    Another way to get text into a header or footer via a range, without necessarily wiping out the contents of the header or footer, is to first define a bookmark as a placeholder in the header or footer.

    Then your code can simply go along the lines of:

    ActiveDocument.Bookmarks("myHeaderBMK").Range.Text = strText

    As with Jeff's method, this way spares you the muss and fuss of actually needing to go into the header or footer.

  5. #5
    Lounger
    Join Date
    Aug 2001
    Location
    Perth,(aka middle of nowhere), Western Australia, Australia
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Screen Updating (VBA/Word/2000)

    When is it better to use Range rather than Selection ? <img src=/S/thinks.gif border=0 alt=thinks width=15 height=15>
    I know it is more flexible to use Range (multiple ranges versus one selection) but you seem to need to know more about which section/paragraph/word/sentence or whatever you are dealing with in general use of it.

    I have always used Selection but is there some other distinct advantage to Range.
    Your code does look a little cleaner given you don't have to worry about the template.

    In short when should I use Range rather than Selection or is there no clear boundary. In this case given we know specifically what we are trying to set (header/footer) it appears to make sense to use the Range approach.

    side point - is there a WdWordDialog constant (or similar) for getting into the footers/headers box to set the footer? I can't find one. If there was then this would provide another solution path for the header insert where user response was required (rather than coding it all yourself).

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Screen Updating (VBA/Word/2000)

    You're stirring up an old debate here! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Generally, it's better to use Range rather than Selection, whenever practical. Range tends to afford you more flexibility and can also run loads faster.

    There aren't any clear boundaries though; more a matter of what works and is practical.

    There are times when Selection is handier to use, or is easier to debug, and there are times when it's the only way to go (for one example, anything to do with drawing layer objects).

    There are folks here who are far more purist about it than me; my feeling is: it's more important to get working code than it is to get elegant code, so - whatever works!

    Re your side point, I'm unaware of anything along those lines.

    Gary

  7. #7
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Screen Updating (VBA/Word/2000)

    Gary,

    A pet subject!

    I prefer Range where possible. Not because I'm a purist- but because I've seen something running using selection, run 4 times faster when using range. This is particularly when copying data, making a selection in on place, selecting aa diffrerent target selection, and pasting. The difference here (and I suspect in many other places) is that the screen is refreshed. Even with ScreenUpdating off, the flickering can be seen.

    Selecting is very popular though, because that's what gets recorded, and that's what most people know. It takes a little while to get into the mindset of using ranges.

    But it took me a while to get into the mindset of VBA after using Wordperfect- and now I wouldn't go back.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  8. #8
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: Screen Updating (VBA/Word/2000)

    Can you expand on what you mean by drawing layer objects?
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  9. #9
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Screen Updating (VBA/Word/2000)

    Sure: drawing layer vs. text layer is another way of saying floating vs. inline.

    Word makes available both a text layer and a drawing layer. A good way to visualize it is that the text layer is the words on a printed page, and the drawing layer is like a transparent sheet (onto which you can place drawing objects), which is overlain over the text on the printed page. (With the added twist that the drawing layer can actually go above or below the text layer.)

    By default when you insert a drawing object into a Word document, it's placed in the drawing layer i.e. it's a floating object.

    Many graphic objects can be converted from floating to inline.

    I don't work much with PowerPoint, but my sense is that PPT is similar to Word's drawing layer.

    It's late so I'm rambling - hope this makes any sense!

    Gary

  10. #10
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: Screen Updating (VBA/Word/2000)

    I think I've got it.
    We used to handle this sort of thing using frames right?
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  11. #11
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Screen Updating (VBA/Word/2000)

    Still do - textboxes are in the drawing layer, while frames are in the text layer - there's times when nothing but a frame will do....

Posting Permissions

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