Consulting

Results 1 to 15 of 15

Thread: Excel workbook activation

  1. #1

    Question Excel workbook activation

    i hv created userform in Excel VBA in which textboxes and other such objects are made. Now I want to copy data from excel sheets to userform manually by copy-paste shortcut keys. Problem is when userform is active, all the workbooks are then deactivated until it is open.
    I want both the workbook and as well as userform to be active, so that I can copy-paste my excel sheets data to userform.

    Plz solve this at ur earliest.

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Hi ilyaskazi,

    Welcome to VBAX. To make both the worksheet and userform active requires Office 2000 or greater. By default your userform is shown modally (which is what you've described) - put False after your "Show" command e.g.:

    Userform1.Show False
    to show it non-modally.

    If you have Office '97 this will not work (although there is another method to simulate non-modal userforms in 97)

    HTH
    John
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  3. #3
    Dear John,

    thanku 4 repling, but the problem is not solved. I m using office XP.

    My form name is "Rules" (userform)

    While...

    Private Sub UserForm_Initialize()
    Dim hWnd As Long
    hWnd = FindWindow(vbNullString, Rules.Caption)
    SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    Userform1.Show False
    End Sub
    I get runtime error="424" telling object required.
    awaiting..
    Last edited by Airborne; 03-17-2005 at 03:00 AM. Reason: Added Wrap[VBA]tags

  4. #4
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by ilyaskazi
    Dear John,

    thanku 4 repling, but the problem is not solved. I m using office XP.

    My form name is "Rules" (userform)

    While...

    Private Sub UserForm_Initialize()
    Dim hWnd As Long
    hWnd = FindWindow(vbNullString, Rules.Caption)
    SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    Userform1.Show False
    End Sub
    I get runtime error="424" telling object required.
    awaiting..
    Hi ilyaskazi,

    In that case it would be...
    Rules.Show False
    But this goes into a standard module (delete the Userform1.Show False from where you have it above).

    In the VBE window got to Insert/Module then paste this code in the module

    Sub ShowForm()
    Rules.Show False
    End Sub
    exit the VBE window and run the code from Tools/Macro/Macros../ShowForm/Run

    John
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  5. #5
    Hi John

    Ur solution to my problem is solved. Thanku. But I cannot switch between my userform window & excel workbook. My Userform opens up in maximize mode. Also when pasting data from Cell, it also pastes ?Enter Note/Symbol? after the value in the textbox.

  6. #6
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Sounds like you want a vbModeless userform?? Not sure if I fully understand you.

    Rules.Load
    Rules.Show vbModeless
    Note this does NOT work in Excel 97, as it doesn't support this method; only in 2000 and greater. You can transversley use vbApplicationModal and vbSystemModal to NOT allow user access to either just the Application or the entire System (other Applications) until the Userform is dealt with.

  7. #7
    firefytr,

    Ur solution is not working. I m using office xp. When I activate Userform (which is maximized), the problem is I cannot switch between my Userform and any open exel workbook by using "ALT + TAB" method.

    Other solution plz..

  8. #8
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi there,

    I wouldn't expect to be able to use that key combination by changing any of the userform properties. Alt+Tab is a windows shortcut to switch between applications. As the userform is part of the application, it wouldn't be picked up by windows.

    I'm sure that we could attempt to overrule the keystroke combination, but have never tried superseeding a windows combination, so am not sure if it would work or not...
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  9. #9
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    If your form is displayed by triggering events you can have a button on th eform that hides it and use


    Private Sub cmdHideButton_Click()
        UserForm1.Hide
      End Sub
    And then in your book have an event proedure that triggers the user form to show again

    Sub SomeEventInExcel
      Userform1.Show
    End Sub

    but remember that a userform loses its variable information when hidden.
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  10. #10
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Quote Originally Posted by sandam
    .. but remeber that a userform looses its variable information when hidden.
    Just as a side note, this can be thwarted. Check out the use of Public/Global variables and the Static method.

  11. #11
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    ahhh. cool
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  12. #12
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    268
    Location
    1. Why post the same question twice?

    Edit: link added - http://www.vbaexpress.com/forum/showthread.php?t=2354
    (Maybe I'm just being grumpy, but I hate to see everyone working twice to solve the same issue.)

    2. What's wrong with using a RefEdit control in the userform to pick up the range of cells you need?

  13. #13
    hi everybody..

    Thanku for solving the problem. All is working fine. Kpuls u r absolutely right but thing is I need the solution and for the same Mr. Sundam has solved with alternate solution.

    Thanku everybody.

    and yes "mr bluecactus" ... I will take the notice of the same..

  14. #14
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Ilyaski,

    So it is solved for you then? Did you know you can mark your own posts solved here? Just see the instructions in my signature!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  15. #15
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Just FYI ...
    Quote Originally Posted by firefytr
    ... Note this does NOT work in Excel 97, as it doesn't support this method; only in 2000 and greater. You can transversley use vbApplicationModal and vbSystemModal to NOT allow user access to either just the Application or the entire System (other Applications) until the Userform is dealt with.
    ... I stand corrected. This is a situation in which a userform can be shown Modeless in Excel 97 (dialog sheets in Excel 95) found here, by Rob Bovey using Windows API. Fwiw.

Posting Permissions

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