Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    171
    Thanks
    3
    Thanked 0 Times in 0 Posts

    How to to bring a document to the front

    Hi all,

    I am trying to activate an open document to bring it to the front , so I can view it on the screen.

    The following is not working. Any ideas?

    Code:
    Dim docCmdInp As Document
    docCmdInp.Application.Activate
    docCmdInp.Application.WindowState = wdWindowStateMaximize
    docCmdInp.Application.WindowState = wdWindowStateNormal
    TIA

    -avi

  2. #2
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    668
    Thanks
    3
    Thanked 21 Times in 19 Posts
    You haven't identified which document you want brought forward. You described docCmdInp as a Document object. You now have to set the document you want to work with as that object. Something like:

    Code:
    Dim docCmdInp As Document
    Set docCmdInp = ActiveDocument  'or give the name of the Document you want to bring forward.
    docCmdInp.Activate
    That should do it.

    Kim

  3. #3
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    171
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks for the answer.

    Sorry. I did in fact program it properly. I just posted an incomplete code sample. I programmed the following. But it does not work.

    Code:
     
    Dim docCmdInp As Document
    Set docCmdInp = Documents(Word_StyleCmdList.doc)
    docCmdInp.Activate
    docCmdInp.Application.Activate
    On another forum, in an old thread, somebody suggested doing the following:

    Code:
    Sub MinimizeAll()
        Dim shell As New shell
        shell.MinimizeAll
    End Sub
    and then activate your doc window. But my VBA does not recognize shell.

    So I would appreciate more help. Any more ideas?

    -avraham

  4. #4
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    668
    Thanks
    3
    Thanked 21 Times in 19 Posts
    Ah, you didn't say anything about Shell -- that's a Windows function and you need to declare it at the top of your code. Something like:
    Code:
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
                    (ByVal hwnd As Long, ByVal lpOperation As String, _
                    ByVal lpFile As String, ByVal lpParameters As String, _
                    ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    I don't know enough about the Shell command to know the command to minimize Word, but someone else will be able to. I'm not sure why you'd want to minimize all documents, and then open one document back up. Unless you're trying to clear your desktop? If you describe what you're trying to do, someone will be better able to help.

    Anyway, I was able to use the following code to open and activate a particular document (I manually minimized two documents before running the code):

    Code:
    Sub ActivationStuff()
    Dim oDoc1 As Document
    Set oDoc1 = Documents("Document1")
    Application.Activate
    Application.WindowState = wdWindowStateNormal
    oDoc2.Activate
    End Sub
    HTH, Kim
    Last edited by kmurdock; 2013-10-20 at 20:23.

Posting Permissions

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