Results 1 to 10 of 10
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how do I hide a window? (Office XP SP3)

    HI

    Im working in a session of Word. I have 1 file open, but I would like to open a 2nd file > perform processing on this 2nd file within that 1session of Word, however I would like to hide or make invisible this 2nd file while my code performs automation ( so the users are unaware that the 2nd file is being processed) with the 1st file still active. How would I do this?

    diana

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how do I hide a window? (Office XP SP3)

    You could switch off screenupdating for the duration of your processing.
    Or you could use something like:

    activedocument.Windows(1).Visible=False
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

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

    Re: how do I hide a window? (Office XP SP3)

    Hi Diana,

    I don't have Office XP, I use Office 2003. But I think this will also work in XP:

    <pre>Sub TempDoc()
    Dim docAct As Document
    Dim docTmp As Document
    Set docAct = ActiveDocument
    Set docTmp = Documents.Add(Visible:=False)
    docTmp.Activate
    <font color=448800>'Do stuff in temporary doc, i.e.:</font color=448800>
    Selection.TypeText "This is a test."
    Debug.Print docAct.Name, docAct.Range.text
    Debug.Print docTmp.Name, docTmp.Range.text
    docTmp.Close SaveChanges:=wdDoNotSaveChanges
    Set docTmp = Nothing
    docAct.Activate
    End Sub</pre>


  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how do I hide a window? (Office XP SP3)

    Hi Jan

    thanks for that.

    For the document I want hidden - I have the following code references eg

    Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
    Selection.Find.ClearFormatting
    Selection.Find.Execute FindText:=strSearch, Forward:=True

    If Selection.Find.Found = True Then
    .....etc

    This wont work will it?

    If I want to work with my hidden window do I have to change 'Selection' to my object eg
    dim docTmp as document

    docTmp.Range.Select
    docTmp.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
    docTmp.Find.ClearFormatting
    docTmp.Find.Execute FindText:=strSearch, Forward:=True

    If docTmp.Find.Found = True Then
    .....etc

    diana :-)

  5. #5
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: how do I hide a window? (Office XP SP3)

    I'd set a range and then work with that range, like this:

    Dim oRng As Word.Range
    Set oRng = docTmp.Range(0, 0)
    oRng.GoTo ...
    oRng.Find...
    etc.

    An awful lot of Selection-based code can be converted to Range-based code by just substituting the range in place of Selection, since many of the methods and properties are the same. Unfortunately, "many" is not the same as "all," so you'll want to consult the VB Help a fair amount if you're not used to working with ranges.

    A side benefit to learning how to work with ranges is that it's considered preferable (in most circumstances) to working with the Selection object, regardless of whether the document you're operating on is a hidden document or the active one in the user's face.

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

    Re: how do I hide a window? (Office XP SP3)

    Hi Diana,

    If you want to open an existing document, rather then creating a new document, then replace the line
    <pre>Set docTmp = Documents.Add(Visible:=False)</pre>

    with
    <pre>Set docTmp = Documents.Open(FileName:="C:MyDoc.doc", Visible:=False)</pre>


    Once the line docTmp.Activate is executed, all subsequent actions are performed on that invisible document. So there is no need to use docTmp as a prefix to every line of code. You can switch between the two documents using Activate until the job is completed and then discard docTmp.
    And I agree with St3333ve regarding Range vs Selection.

  7. #7
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: how do I hide a window? (Office XP SP3)

    As a follow-up to yesterday's quick post, here are a few pointers if you're relatively new to working with ranges:

    Range methods don

  8. #8
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how do I hide a window? (Office XP SP3)

    HI - Thankyou for that info. I also found working with 'Selection' easier. diana :-)

  9. #9
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: how do I hide a window? (Office XP SP3)

    You wouldn't use things like .Activate and Selection in a hidden window - because these relate to things the user can see. It works fine with Ranges and manipulation of objects.

    StuartR

  10. #10
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how do I hide a window? (Office XP SP3)

    Edited by <!profile=StuartR>StuartR<!/profile>. Added <!t><!/t> and <!t><!/t> to make links active. See <!help=19>Help 19<!/help>.[/i]

    Hi - as a follow up too....

    When ever I made my window hidden >the result was I was getting errors or Word behaving incorreclty.
    Set docTmp = Documents.Open(FileName:=strFilename, Format:=wdOpenFormatAuto, Encoding:=1252, Visible:=False)
    docTmp.Activate
    ...process the file...code to move selection Up & Down etc

    Yet when I made my window visible > the result was that Word was behaving correctly.'
    docTmp.Activate
    ...process the file...code to move selection Up & Down etc

    Ive found that there are bugs with code when Word is not visible & working with Selection.MoveUp & down.
    http://support.microsoft.com/kb/q235876/
    http://www.google.com.au/search?q=cache:1k...false&hl=en

    Diana <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

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