Consulting

Results 1 to 7 of 7

Thread: How to hide the workbook while exeuting macro?

  1. #1
    VBAX Regular
    Joined
    Apr 2008
    Posts
    51
    Location

    How to hide the workbook while exeuting macro?

    Hi,

    How can i hide the workbook named WrkBk1.xls, when i have opened the WrkBk2.xls from the macro of WrkBk1.xls. Macro in WrkBk1.xls will process the data in WrkBk2.xls during which i want user to not able to select the WrkBk1.xls.So i thought of hiding it or when user selects it, it wont let user select the WrkBk1.xls during execution.

    And once the execution is done i will close WrkBk2.xls and in WrkBk1.xls i will show the message done.

    Regards,
    Krrishna
    Last edited by gopi09_m; 05-17-2008 at 08:26 PM.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Windows("WrkBk1.xls").Visible - False
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Apr 2008
    Posts
    51
    Location
    Windows("WrkBk1.xls").Visible = False
    Its throwing the below error..
    Run-time error '9'
    subscript out of range

  4. #4
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,194
    Location
    Have you thought of something like this

    [VBA]Windows("Book1").WindowState = xlMinimized
    MsgBox "Hello"
    Workbooks.Add
    MsgBox "Hello"
    Windows("Book4").Close False
    MsgBox "Hello"
    Windows("Book1").WindowState = xlMaximized
    End Sub[/VBA]

    its just some random code between two windowstates, you could adjust it for your needs.

    Hope this helps

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by gopi09_m
    Windows("WrkBk1.xls").Visible = False
    Its throwing the below error..
    Run-time error '9'
    subscript out of range
    That suggests that you do ot have a workbook by that name.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Quote Originally Posted by xld
    That suggests that you do ot have a workbook by that name.
    If you are trying the code on an unsaved workbook i.e you have just opened Excel and see Book1 then the .xls extension does not apply as you haven't actually saved it as a type.

    Try this:
    Open a new workbook, go to the VBE and add a sub, now add this line:
    [VBA]
    Windows("book1.xls").Visible = false
    [/VBA]run the sub and you get Runtime error 9, Subscript out of range, now change the line to this:
    [VBA]
    Windows("book1").Visible = false
    [/VBA]and it works fine!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  7. #7
    VBAX Regular
    Joined
    Apr 2008
    Posts
    51
    Location
    Thank you.Thats exactly what i required.

Posting Permissions

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