none
VB.NET Bring one Excel workbook to the top over another RRS feed

  • Question

  • I have created a COM addin for Excel. The user starts in one workbook (wbStart), and then the program creates a new workbook (wbNew) and adds information to it.    I want the wbNew to be the top window.   When I look at the Task Master, I see that each workbook is a different instance of Excel. 

    At the end of the sub that creates the new workbook and adds information, I've tried:

    wbNew.Activate()

    But this does not work.  The wbStart stays on top.  The program never uses the wbStart again after creating wbNew.  When I create a new variable (wbAct) and set the thisAPP.ActiveWorkbook to that variable, it shows that wbNew is actually the active workbook by the end of the procedure.  However, it still does not come to the top.  wbStart stays on top.

    EDIT:  I found that the newWB stays on top until the Me.Close runs on a form that is used to get info from the user to make the newWB.   If I don't close the form, the newWB stays on top, but the form for some reason prevents working in Excel until it is closed by the user. 

    Any suggestions on how to make wbNew come to the front after the form is closed?  I've tried newWB.Activate() after the Me.Close, but it doesn't work. 


    Gina




    • Edited by Gina1111 Tuesday, December 9, 2014 11:45 PM
    Tuesday, December 9, 2014 10:31 PM

Answers

  • For some absurd reason, neither of these works alone, but when done in sequence, it works:

    newWB.Activate()
    newWB.Application.Workbooks(newWB.Name).Activate()
    Does anybody have an idea why?


    Gina


    • Edited by Gina1111 Wednesday, December 10, 2014 12:34 AM
    • Marked as answer by Gina1111 Wednesday, December 10, 2014 3:17 PM
    Wednesday, December 10, 2014 12:33 AM

All replies

  • For some absurd reason, neither of these works alone, but when done in sequence, it works:

    newWB.Activate()
    newWB.Application.Workbooks(newWB.Name).Activate()
    Does anybody have an idea why?


    Gina


    • Edited by Gina1111 Wednesday, December 10, 2014 12:34 AM
    • Marked as answer by Gina1111 Wednesday, December 10, 2014 3:17 PM
    Wednesday, December 10, 2014 12:33 AM
  • Hi Gina1111,

    Based on my understanding, when we create a new workbook, the workbook should be active. Would you mind sharing a sample project to help us to reproduce this issue?

    You can upload it via OneDrive and please remove the sensitive information before you upload.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 10, 2014 5:25 AM
    Moderator