+ Reply to Thread
Results 1 to 15 of 15

WorkBook Activate event not working

  1. #1

    WorkBook Activate event not working

    Hello,

    I have an excel addin (.xla) file under excel startup folder (ie,
    \office11\startup), where I have defined App_WorkbookActivate event.
    This macro executes fine when I open the excel file from explorer. But
    when I open the file from automation, it does not execute.
    The code is as follows,

    Application.EnableEvent(True)
    ActiveWorkbook = AllWorkbooks.Open("filename")
    ActiveWorkbook.RunAutoMacros(3)

    Any suggestions would help!

    Thankyou.


  2. #2
    Don Guillett
    Guest

    Re: WorkBook Activate event not working

    >>Application.EnableEvent(True)
    Application.EnableEventS=true


    Here is one I use with a double_click event to goto a workbook whose name is
    typed in a cell.

    Sub GetWorkbook()
    If ActiveCell.Value = "" Then Exit Sub
    workbookname = ActiveCell.Value
    On Error GoTo OpenWorkbook
    Windows(workbookname & ".xls").Activate
    Exit Sub
    OpenWorkbook:
    Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen
    End Sub
    --
    Don Guillett
    SalesAid Software
    [email protected]
    <[email protected]> wrote in message
    news:[email protected]...
    > Hello,
    >
    > I have an excel addin (.xla) file under excel startup folder (ie,
    > \office11\startup), where I have defined App_WorkbookActivate event.
    > This macro executes fine when I open the excel file from explorer. But
    > when I open the file from automation, it does not execute.
    > The code is as follows,
    >
    > Application.EnableEvent(True)
    > ActiveWorkbook = AllWorkbooks.Open("filename")
    > ActiveWorkbook.RunAutoMacros(3)
    >
    > Any suggestions would help!
    >
    > Thankyou.
    >




  3. #3
    Tom Ogilvy
    Guest

    RE: WorkBook Activate event not working

    Activeworkbook is a predefined reference to the workbook that is active. I
    wouldn't try setting it to anything.

    The fact that you show that code and say that it works in any situation
    makes your whole presentation suspect.

    Of course Don has already pointed out an additional offending line:
    >Application.EnableEvent(True)

    --
    Regards,
    Tom Ogilvy


    "[email protected]" wrote:

    > Hello,
    >
    > I have an excel addin (.xla) file under excel startup folder (ie,
    > \office11\startup), where I have defined App_WorkbookActivate event.
    > This macro executes fine when I open the excel file from explorer. But
    > when I open the file from automation, it does not execute.
    > The code is as follows,
    >
    > Application.EnableEvent(True)
    > ActiveWorkbook = AllWorkbooks.Open("filename")
    > ActiveWorkbook.RunAutoMacros(3)
    >
    > Any suggestions would help!
    >
    > Thankyou.
    >
    >


  4. #4

    Re: WorkBook Activate event not working


    Don Guillett wrote:
    > >>Application.EnableEvent(True)

    > Application.EnableEventS=true
    >
    >
    > Here is one I use with a double_click event to goto a workbook whose name is
    > typed in a cell.
    >
    > Sub GetWorkbook()
    > If ActiveCell.Value = "" Then Exit Sub
    > workbookname = ActiveCell.Value
    > On Error GoTo OpenWorkbook
    > Windows(workbookname & ".xls").Activate
    > Exit Sub
    > OpenWorkbook:
    > Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen
    > End Sub
    > --
    > Don Guillett
    > SalesAid Software
    > [email protected]
    > <[email protected]> wrote in message
    > news:[email protected]...
    > > Hello,
    > >
    > > I have an excel addin (.xla) file under excel startup folder (ie,
    > > \office11\startup), where I have defined App_WorkbookActivate event.
    > > This macro executes fine when I open the excel file from explorer. But
    > > when I open the file from automation, it does not execute.
    > > The code is as follows,
    > >
    > > Application.EnableEvent(True)
    > > ActiveWorkbook = AllWorkbooks.Open("filename")
    > > ActiveWorkbook.RunAutoMacros(3)
    > >
    > > Any suggestions would help!
    > >
    > > Thankyou.
    > >


    Thanks for your reply.
    The code looks similar, except for
    Windows(workbookname & ".xls").Activate
    What does the above line of code do?
    I am writing in c++ and I am not sure what is the code equivalent to
    the above in c++?
    I understand Workbook activate is executed when workopen is opened.


  5. #5
    Don Guillett
    Guest

    Re: WorkBook Activate event not working

    I don't do C++. This is visual basic for applications VBA

    --
    Don Guillett
    SalesAid Software
    [email protected]
    <[email protected]> wrote in message
    news:[email protected]...
    >
    > Don Guillett wrote:
    >> >>Application.EnableEvent(True)

    >> Application.EnableEventS=true
    >>
    >>
    >> Here is one I use with a double_click event to goto a workbook whose name
    >> is
    >> typed in a cell.
    >>
    >> Sub GetWorkbook()
    >> If ActiveCell.Value = "" Then Exit Sub
    >> workbookname = ActiveCell.Value
    >> On Error GoTo OpenWorkbook
    >> Windows(workbookname & ".xls").Activate
    >> Exit Sub
    >> OpenWorkbook:
    >> Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen
    >> End Sub
    >> --
    >> Don Guillett
    >> SalesAid Software
    >> [email protected]
    >> <[email protected]> wrote in message
    >> news:[email protected]...
    >> > Hello,
    >> >
    >> > I have an excel addin (.xla) file under excel startup folder (ie,
    >> > \office11\startup), where I have defined App_WorkbookActivate event.
    >> > This macro executes fine when I open the excel file from explorer. But
    >> > when I open the file from automation, it does not execute.
    >> > The code is as follows,
    >> >
    >> > Application.EnableEvent(True)
    >> > ActiveWorkbook = AllWorkbooks.Open("filename")
    >> > ActiveWorkbook.RunAutoMacros(3)
    >> >
    >> > Any suggestions would help!
    >> >
    >> > Thankyou.
    >> >

    >
    > Thanks for your reply.
    > The code looks similar, except for
    > Windows(workbookname & ".xls").Activate
    > What does the above line of code do?
    > I am writing in c++ and I am not sure what is the code equivalent to
    > the above in c++?
    > I understand Workbook activate is executed when workopen is opened.
    >




  6. #6

    Re: WorkBook Activate event not working


    [email protected] wrote:
    > Don Guillett wrote:
    > > >>Application.EnableEvent(True)

    > > Application.EnableEventS=true
    > >
    > >
    > > Here is one I use with a double_click event to goto a workbook whose name is
    > > typed in a cell.
    > >
    > > Sub GetWorkbook()
    > > If ActiveCell.Value = "" Then Exit Sub
    > > workbookname = ActiveCell.Value
    > > On Error GoTo OpenWorkbook
    > > Windows(workbookname & ".xls").Activate
    > > Exit Sub
    > > OpenWorkbook:
    > > Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen
    > > End Sub
    > > --
    > > Don Guillett
    > > SalesAid Software
    > > [email protected]
    > > <[email protected]> wrote in message
    > > news:[email protected]...
    > > > Hello,
    > > >
    > > > I have an excel addin (.xla) file under excel startup folder (ie,
    > > > \office11\startup), where I have defined App_WorkbookActivate event.
    > > > This macro executes fine when I open the excel file from explorer. But
    > > > when I open the file from automation, it does not execute.
    > > > The code is as follows,
    > > >
    > > > Application.EnableEvent(True)
    > > > ActiveWorkbook = AllWorkbooks.Open("filename")
    > > > ActiveWorkbook.RunAutoMacros(3)
    > > >
    > > > Any suggestions would help!
    > > >
    > > > Thankyou.
    > > >

    >
    > Thanks for your reply.
    > The code looks similar, except for
    > Windows(workbookname & ".xls").Activate
    > What does the above line of code do?
    > I am writing in c++ and I am not sure what is the code equivalent to
    > the above in c++?
    > I understand Workbook activate is executed when workopen is opened.


    I am sorry, I did have EnableEvents(True) in my code, it was a typo.
    And I am coding in c++, so ActiveWorkbook is a object variable in my
    code. It has nothing to do with the predefined reference.
    The macro itself that I have defined in the xla file is as follows,

    Private Sub App_WorkbookActivate(ByVal Wb As Workbook)

    Application.SendKeys ("%C")
    Application.Dialogs(xlDialogPrintPreview).Show

    Dim currentWindow As Window
    For Each currentWindow In Wb.Windows
    currentWindow.View = xlPageBreakPreview
    Next currentWindow

    End Sub

    The xla file is in the excel start up folder, so it gets executed when
    I open the file from explorer. However, when I try to open the file
    from automation, it does not execute the activate event.


  7. #7
    Tom Ogilvy
    Guest

    Re: WorkBook Activate event not working

    I see your deeply engaged with Don in some heavy duty topics, but just for
    interest, Addins and files in the xlStart directory are not loaded when Excel
    is started programmatically.

    --
    Regards,
    Tom Ogilvy





    "[email protected]" wrote:

    >
    > Don Guillett wrote:
    > > >>Application.EnableEvent(True)

    > > Application.EnableEventS=true
    > >
    > >
    > > Here is one I use with a double_click event to goto a workbook whose name is
    > > typed in a cell.
    > >
    > > Sub GetWorkbook()
    > > If ActiveCell.Value = "" Then Exit Sub
    > > workbookname = ActiveCell.Value
    > > On Error GoTo OpenWorkbook
    > > Windows(workbookname & ".xls").Activate
    > > Exit Sub
    > > OpenWorkbook:
    > > Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen
    > > End Sub
    > > --
    > > Don Guillett
    > > SalesAid Software
    > > [email protected]
    > > <[email protected]> wrote in message
    > > news:[email protected]...
    > > > Hello,
    > > >
    > > > I have an excel addin (.xla) file under excel startup folder (ie,
    > > > \office11\startup), where I have defined App_WorkbookActivate event.
    > > > This macro executes fine when I open the excel file from explorer. But
    > > > when I open the file from automation, it does not execute.
    > > > The code is as follows,
    > > >
    > > > Application.EnableEvent(True)
    > > > ActiveWorkbook = AllWorkbooks.Open("filename")
    > > > ActiveWorkbook.RunAutoMacros(3)
    > > >
    > > > Any suggestions would help!
    > > >
    > > > Thankyou.
    > > >

    >
    > Thanks for your reply.
    > The code looks similar, except for
    > Windows(workbookname & ".xls").Activate
    > What does the above line of code do?
    > I am writing in c++ and I am not sure what is the code equivalent to
    > the above in c++?
    > I understand Workbook activate is executed when workopen is opened.
    >
    >


  8. #8
    ksr
    Guest

    Re: WorkBook Activate event not working

    Thanks.
    Is there any way I can have this macro execute when excel is started
    programatically?


    Tom Ogilvy wrote:
    > I see your deeply engaged with Don in some heavy duty topics, but just for
    > interest, Addins and files in the xlStart directory are not loaded when Excel
    > is started programmatically.
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    >
    >
    >
    > "[email protected]" wrote:
    >
    > >
    > > Don Guillett wrote:
    > > > >>Application.EnableEvent(True)
    > > > Application.EnableEventS=true
    > > >
    > > >
    > > > Here is one I use with a double_click event to goto a workbook whose name is
    > > > typed in a cell.
    > > >
    > > > Sub GetWorkbook()
    > > > If ActiveCell.Value = "" Then Exit Sub
    > > > workbookname = ActiveCell.Value
    > > > On Error GoTo OpenWorkbook
    > > > Windows(workbookname & ".xls").Activate
    > > > Exit Sub
    > > > OpenWorkbook:
    > > > Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen
    > > > End Sub
    > > > --
    > > > Don Guillett
    > > > SalesAid Software
    > > > [email protected]
    > > > <[email protected]> wrote in message
    > > > news:[email protected]...
    > > > > Hello,
    > > > >
    > > > > I have an excel addin (.xla) file under excel startup folder (ie,
    > > > > \office11\startup), where I have defined App_WorkbookActivate event.
    > > > > This macro executes fine when I open the excel file from explorer. But
    > > > > when I open the file from automation, it does not execute.
    > > > > The code is as follows,
    > > > >
    > > > > Application.EnableEvent(True)
    > > > > ActiveWorkbook = AllWorkbooks.Open("filename")
    > > > > ActiveWorkbook.RunAutoMacros(3)
    > > > >
    > > > > Any suggestions would help!
    > > > >
    > > > > Thankyou.
    > > > >

    > >
    > > Thanks for your reply.
    > > The code looks similar, except for
    > > Windows(workbookname & ".xls").Activate
    > > What does the above line of code do?
    > > I am writing in c++ and I am not sure what is the code equivalent to
    > > the above in c++?
    > > I understand Workbook activate is executed when workopen is opened.
    > >
    > >



  9. #9
    Don Guillett
    Guest

    Re: WorkBook Activate event not working

    Tom, please feel free to step in and help the OP

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "Tom Ogilvy" <[email protected]> wrote in message
    news:[email protected]...
    >I see your deeply engaged with Don in some heavy duty topics, but just for
    > interest, Addins and files in the xlStart directory are not loaded when
    > Excel
    > is started programmatically.
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    >
    >
    >
    > "[email protected]" wrote:
    >
    >>
    >> Don Guillett wrote:
    >> > >>Application.EnableEvent(True)
    >> > Application.EnableEventS=true
    >> >
    >> >
    >> > Here is one I use with a double_click event to goto a workbook whose
    >> > name is
    >> > typed in a cell.
    >> >
    >> > Sub GetWorkbook()
    >> > If ActiveCell.Value = "" Then Exit Sub
    >> > workbookname = ActiveCell.Value
    >> > On Error GoTo OpenWorkbook
    >> > Windows(workbookname & ".xls").Activate
    >> > Exit Sub
    >> > OpenWorkbook:
    >> > Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen
    >> > End Sub
    >> > --
    >> > Don Guillett
    >> > SalesAid Software
    >> > [email protected]
    >> > <[email protected]> wrote in message
    >> > news:[email protected]...
    >> > > Hello,
    >> > >
    >> > > I have an excel addin (.xla) file under excel startup folder (ie,
    >> > > \office11\startup), where I have defined App_WorkbookActivate event.
    >> > > This macro executes fine when I open the excel file from explorer.
    >> > > But
    >> > > when I open the file from automation, it does not execute.
    >> > > The code is as follows,
    >> > >
    >> > > Application.EnableEvent(True)
    >> > > ActiveWorkbook = AllWorkbooks.Open("filename")
    >> > > ActiveWorkbook.RunAutoMacros(3)
    >> > >
    >> > > Any suggestions would help!
    >> > >
    >> > > Thankyou.
    >> > >

    >>
    >> Thanks for your reply.
    >> The code looks similar, except for
    >> Windows(workbookname & ".xls").Activate
    >> What does the above line of code do?
    >> I am writing in c++ and I am not sure what is the code equivalent to
    >> the above in c++?
    >> I understand Workbook activate is executed when workopen is opened.
    >>
    >>




  10. #10
    Tom Ogilvy
    Guest

    Re: WorkBook Activate event not working

    Sure, in the same code that opens the workbook, open the addin as well.

    As an alternative, you can load it as an addin, but opening it should have
    the same effect.

    --
    Regards,
    Tom Ogilvy


    "ksr" wrote:

    > Thanks.
    > Is there any way I can have this macro execute when excel is started
    > programatically?
    >
    >
    > Tom Ogilvy wrote:
    > > I see your deeply engaged with Don in some heavy duty topics, but just for
    > > interest, Addins and files in the xlStart directory are not loaded when Excel
    > > is started programmatically.
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > >
    > >
    > >
    > > "[email protected]" wrote:
    > >
    > > >
    > > > Don Guillett wrote:
    > > > > >>Application.EnableEvent(True)
    > > > > Application.EnableEventS=true
    > > > >
    > > > >
    > > > > Here is one I use with a double_click event to goto a workbook whose name is
    > > > > typed in a cell.
    > > > >
    > > > > Sub GetWorkbook()
    > > > > If ActiveCell.Value = "" Then Exit Sub
    > > > > workbookname = ActiveCell.Value
    > > > > On Error GoTo OpenWorkbook
    > > > > Windows(workbookname & ".xls").Activate
    > > > > Exit Sub
    > > > > OpenWorkbook:
    > > > > Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen
    > > > > End Sub
    > > > > --
    > > > > Don Guillett
    > > > > SalesAid Software
    > > > > [email protected]
    > > > > <[email protected]> wrote in message
    > > > > news:[email protected]...
    > > > > > Hello,
    > > > > >
    > > > > > I have an excel addin (.xla) file under excel startup folder (ie,
    > > > > > \office11\startup), where I have defined App_WorkbookActivate event.
    > > > > > This macro executes fine when I open the excel file from explorer. But
    > > > > > when I open the file from automation, it does not execute.
    > > > > > The code is as follows,
    > > > > >
    > > > > > Application.EnableEvent(True)
    > > > > > ActiveWorkbook = AllWorkbooks.Open("filename")
    > > > > > ActiveWorkbook.RunAutoMacros(3)
    > > > > >
    > > > > > Any suggestions would help!
    > > > > >
    > > > > > Thankyou.
    > > > > >
    > > >
    > > > Thanks for your reply.
    > > > The code looks similar, except for
    > > > Windows(workbookname & ".xls").Activate
    > > > What does the above line of code do?
    > > > I am writing in c++ and I am not sure what is the code equivalent to
    > > > the above in c++?
    > > > I understand Workbook activate is executed when workopen is opened.
    > > >
    > > >

    >
    >


  11. #11
    ksr
    Guest

    Re: WorkBook Activate event not working

    Thankyou,
    Can you give me some example code on how to open an addin? or how to
    load as an addin?

    Tom Ogilvy wrote:
    > Sure, in the same code that opens the workbook, open the addin as well.
    >
    > As an alternative, you can load it as an addin, but opening it should have
    > the same effect.
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "ksr" wrote:
    >
    > > Thanks.
    > > Is there any way I can have this macro execute when excel is started
    > > programatically?
    > >
    > >
    > > Tom Ogilvy wrote:
    > > > I see your deeply engaged with Don in some heavy duty topics, but just for
    > > > interest, Addins and files in the xlStart directory are not loaded when Excel
    > > > is started programmatically.
    > > >
    > > > --
    > > > Regards,
    > > > Tom Ogilvy
    > > >
    > > >
    > > >
    > > >
    > > >
    > > > "[email protected]" wrote:
    > > >
    > > > >
    > > > > Don Guillett wrote:
    > > > > > >>Application.EnableEvent(True)
    > > > > > Application.EnableEventS=true
    > > > > >
    > > > > >
    > > > > > Here is one I use with a double_click event to goto a workbook whose name is
    > > > > > typed in a cell.
    > > > > >
    > > > > > Sub GetWorkbook()
    > > > > > If ActiveCell.Value = "" Then Exit Sub
    > > > > > workbookname = ActiveCell.Value
    > > > > > On Error GoTo OpenWorkbook
    > > > > > Windows(workbookname & ".xls").Activate
    > > > > > Exit Sub
    > > > > > OpenWorkbook:
    > > > > > Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen
    > > > > > End Sub
    > > > > > --
    > > > > > Don Guillett
    > > > > > SalesAid Software
    > > > > > [email protected]
    > > > > > <[email protected]> wrote in message
    > > > > > news:[email protected]...
    > > > > > > Hello,
    > > > > > >
    > > > > > > I have an excel addin (.xla) file under excel startup folder (ie,
    > > > > > > \office11\startup), where I have defined App_WorkbookActivate event.
    > > > > > > This macro executes fine when I open the excel file from explorer. But
    > > > > > > when I open the file from automation, it does not execute.
    > > > > > > The code is as follows,
    > > > > > >
    > > > > > > Application.EnableEvent(True)
    > > > > > > ActiveWorkbook = AllWorkbooks.Open("filename")
    > > > > > > ActiveWorkbook.RunAutoMacros(3)
    > > > > > >
    > > > > > > Any suggestions would help!
    > > > > > >
    > > > > > > Thankyou.
    > > > > > >
    > > > >
    > > > > Thanks for your reply.
    > > > > The code looks similar, except for
    > > > > Windows(workbookname & ".xls").Activate
    > > > > What does the above line of code do?
    > > > > I am writing in c++ and I am not sure what is the code equivalent to
    > > > > the above in c++?
    > > > > I understand Workbook activate is executed when workopen is opened.
    > > > >
    > > > >

    > >
    > >



  12. #12
    ksr
    Guest

    Re: WorkBook Activate event not working

    I added code to open the addin, but I can't get it to work. Is it
    sufficient to add code to open the addin or should I make a call to
    something else?

    Thankyou.

    ksr wrote:
    > Thankyou,
    > Can you give me some example code on how to open an addin? or how to
    > load as an addin?
    >
    > Tom Ogilvy wrote:
    > > Sure, in the same code that opens the workbook, open the addin as well.
    > >
    > > As an alternative, you can load it as an addin, but opening it should have
    > > the same effect.
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "ksr" wrote:
    > >
    > > > Thanks.
    > > > Is there any way I can have this macro execute when excel is started
    > > > programatically?
    > > >
    > > >
    > > > Tom Ogilvy wrote:
    > > > > I see your deeply engaged with Don in some heavy duty topics, but just for
    > > > > interest, Addins and files in the xlStart directory are not loaded when Excel
    > > > > is started programmatically.
    > > > >
    > > > > --
    > > > > Regards,
    > > > > Tom Ogilvy
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > > "[email protected]" wrote:
    > > > >
    > > > > >
    > > > > > Don Guillett wrote:
    > > > > > > >>Application.EnableEvent(True)
    > > > > > > Application.EnableEventS=true
    > > > > > >
    > > > > > >
    > > > > > > Here is one I use with a double_click event to goto a workbook whose name is
    > > > > > > typed in a cell.
    > > > > > >
    > > > > > > Sub GetWorkbook()
    > > > > > > If ActiveCell.Value = "" Then Exit Sub
    > > > > > > workbookname = ActiveCell.Value
    > > > > > > On Error GoTo OpenWorkbook
    > > > > > > Windows(workbookname & ".xls").Activate
    > > > > > > Exit Sub
    > > > > > > OpenWorkbook:
    > > > > > > Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen
    > > > > > > End Sub
    > > > > > > --
    > > > > > > Don Guillett
    > > > > > > SalesAid Software
    > > > > > > [email protected]
    > > > > > > <[email protected]> wrote in message
    > > > > > > news:[email protected]...
    > > > > > > > Hello,
    > > > > > > >
    > > > > > > > I have an excel addin (.xla) file under excel startup folder (ie,
    > > > > > > > \office11\startup), where I have defined App_WorkbookActivate event.
    > > > > > > > This macro executes fine when I open the excel file from explorer. But
    > > > > > > > when I open the file from automation, it does not execute.
    > > > > > > > The code is as follows,
    > > > > > > >
    > > > > > > > Application.EnableEvent(True)
    > > > > > > > ActiveWorkbook = AllWorkbooks.Open("filename")
    > > > > > > > ActiveWorkbook.RunAutoMacros(3)
    > > > > > > >
    > > > > > > > Any suggestions would help!
    > > > > > > >
    > > > > > > > Thankyou.
    > > > > > > >
    > > > > >
    > > > > > Thanks for your reply.
    > > > > > The code looks similar, except for
    > > > > > Windows(workbookname & ".xls").Activate
    > > > > > What does the above line of code do?
    > > > > > I am writing in c++ and I am not sure what is the code equivalent to
    > > > > > the above in c++?
    > > > > > I understand Workbook activate is executed when workopen is opened.
    > > > > >
    > > > > >
    > > >
    > > >



  13. #13
    Tom Ogilvy
    Guest

    Re: WorkBook Activate event not working

    workbooks.Open "C:\MyFolder\Myfile.xla"

    here is some code by Dana De Louis that loads the solver addin. If you want
    to load the addin, then you can parts of this code as an example.


    Sub SolverInstall()
    '// Dana DeLouis
    Dim wb As Workbook

    On Error Resume Next
    ' Set a Reference to the workbook that will hold Solver
    Set wb = ActiveWorkbook

    With wb.VBProject.References
    .Remove .Item("SOLVER")
    End With

    With AddIns("Solver Add-In")
    .Installed = False
    .Installed = True
    wb.VBProject.References.AddFromFile .FullName
    End With
    End Sub


    --
    Regards,
    Tom Ogilvy



    "ksr" wrote:

    > Thankyou,
    > Can you give me some example code on how to open an addin? or how to
    > load as an addin?
    >
    > Tom Ogilvy wrote:
    > > Sure, in the same code that opens the workbook, open the addin as well.
    > >
    > > As an alternative, you can load it as an addin, but opening it should have
    > > the same effect.
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "ksr" wrote:
    > >
    > > > Thanks.
    > > > Is there any way I can have this macro execute when excel is started
    > > > programatically?
    > > >
    > > >
    > > > Tom Ogilvy wrote:
    > > > > I see your deeply engaged with Don in some heavy duty topics, but just for
    > > > > interest, Addins and files in the xlStart directory are not loaded when Excel
    > > > > is started programmatically.
    > > > >
    > > > > --
    > > > > Regards,
    > > > > Tom Ogilvy
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > > "[email protected]" wrote:
    > > > >
    > > > > >
    > > > > > Don Guillett wrote:
    > > > > > > >>Application.EnableEvent(True)
    > > > > > > Application.EnableEventS=true
    > > > > > >
    > > > > > >
    > > > > > > Here is one I use with a double_click event to goto a workbook whose name is
    > > > > > > typed in a cell.
    > > > > > >
    > > > > > > Sub GetWorkbook()
    > > > > > > If ActiveCell.Value = "" Then Exit Sub
    > > > > > > workbookname = ActiveCell.Value
    > > > > > > On Error GoTo OpenWorkbook
    > > > > > > Windows(workbookname & ".xls").Activate
    > > > > > > Exit Sub
    > > > > > > OpenWorkbook:
    > > > > > > Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen
    > > > > > > End Sub
    > > > > > > --
    > > > > > > Don Guillett
    > > > > > > SalesAid Software
    > > > > > > [email protected]
    > > > > > > <[email protected]> wrote in message
    > > > > > > news:[email protected]...
    > > > > > > > Hello,
    > > > > > > >
    > > > > > > > I have an excel addin (.xla) file under excel startup folder (ie,
    > > > > > > > \office11\startup), where I have defined App_WorkbookActivate event.
    > > > > > > > This macro executes fine when I open the excel file from explorer. But
    > > > > > > > when I open the file from automation, it does not execute.
    > > > > > > > The code is as follows,
    > > > > > > >
    > > > > > > > Application.EnableEvent(True)
    > > > > > > > ActiveWorkbook = AllWorkbooks.Open("filename")
    > > > > > > > ActiveWorkbook.RunAutoMacros(3)
    > > > > > > >
    > > > > > > > Any suggestions would help!
    > > > > > > >
    > > > > > > > Thankyou.
    > > > > > > >
    > > > > >
    > > > > > Thanks for your reply.
    > > > > > The code looks similar, except for
    > > > > > Windows(workbookname & ".xls").Activate
    > > > > > What does the above line of code do?
    > > > > > I am writing in c++ and I am not sure what is the code equivalent to
    > > > > > the above in c++?
    > > > > > I understand Workbook activate is executed when workopen is opened.
    > > > > >
    > > > > >
    > > >
    > > >

    >
    >


  14. #14
    ksr
    Guest

    Re: WorkBook Activate event not working

    Thankyou all so very much. I appreciate your help.
    I got it to work. I open the addin and then open the workbook and the
    macro executes now.

    ksr wrote:
    > I added code to open the addin, but I can't get it to work. Is it
    > sufficient to add code to open the addin or should I make a call to
    > something else?
    >
    > Thankyou.
    >
    > ksr wrote:
    > > Thankyou,
    > > Can you give me some example code on how to open an addin? or how to
    > > load as an addin?
    > >
    > > Tom Ogilvy wrote:
    > > > Sure, in the same code that opens the workbook, open the addin as well.
    > > >
    > > > As an alternative, you can load it as an addin, but opening it should have
    > > > the same effect.
    > > >
    > > > --
    > > > Regards,
    > > > Tom Ogilvy
    > > >
    > > >
    > > > "ksr" wrote:
    > > >
    > > > > Thanks.
    > > > > Is there any way I can have this macro execute when excel is started
    > > > > programatically?
    > > > >
    > > > >
    > > > > Tom Ogilvy wrote:
    > > > > > I see your deeply engaged with Don in some heavy duty topics, but just for
    > > > > > interest, Addins and files in the xlStart directory are not loaded when Excel
    > > > > > is started programmatically.
    > > > > >
    > > > > > --
    > > > > > Regards,
    > > > > > Tom Ogilvy
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > > "[email protected]" wrote:
    > > > > >
    > > > > > >
    > > > > > > Don Guillett wrote:
    > > > > > > > >>Application.EnableEvent(True)
    > > > > > > > Application.EnableEventS=true
    > > > > > > >
    > > > > > > >
    > > > > > > > Here is one I use with a double_click event to goto a workbook whose name is
    > > > > > > > typed in a cell.
    > > > > > > >
    > > > > > > > Sub GetWorkbook()
    > > > > > > > If ActiveCell.Value = "" Then Exit Sub
    > > > > > > > workbookname = ActiveCell.Value
    > > > > > > > On Error GoTo OpenWorkbook
    > > > > > > > Windows(workbookname & ".xls").Activate
    > > > > > > > Exit Sub
    > > > > > > > OpenWorkbook:
    > > > > > > > Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen
    > > > > > > > End Sub
    > > > > > > > --
    > > > > > > > Don Guillett
    > > > > > > > SalesAid Software
    > > > > > > > [email protected]
    > > > > > > > <[email protected]> wrote in message
    > > > > > > > news:[email protected]...
    > > > > > > > > Hello,
    > > > > > > > >
    > > > > > > > > I have an excel addin (.xla) file under excel startup folder (ie,
    > > > > > > > > \office11\startup), where I have defined App_WorkbookActivate event.
    > > > > > > > > This macro executes fine when I open the excel file from explorer. But
    > > > > > > > > when I open the file from automation, it does not execute.
    > > > > > > > > The code is as follows,
    > > > > > > > >
    > > > > > > > > Application.EnableEvent(True)
    > > > > > > > > ActiveWorkbook = AllWorkbooks.Open("filename")
    > > > > > > > > ActiveWorkbook.RunAutoMacros(3)
    > > > > > > > >
    > > > > > > > > Any suggestions would help!
    > > > > > > > >
    > > > > > > > > Thankyou.
    > > > > > > > >
    > > > > > >
    > > > > > > Thanks for your reply.
    > > > > > > The code looks similar, except for
    > > > > > > Windows(workbookname & ".xls").Activate
    > > > > > > What does the above line of code do?
    > > > > > > I am writing in c++ and I am not sure what is the code equivalent to
    > > > > > > the above in c++?
    > > > > > > I understand Workbook activate is executed when workopen is opened.
    > > > > > >
    > > > > > >
    > > > >
    > > > >



  15. #15
    Tom Ogilvy
    Guest

    Re: WorkBook Activate event not working

    Yea!!!

    --
    Regards,
    Tom Ogilvy


    "ksr" wrote:

    > Thankyou all so very much. I appreciate your help.
    > I got it to work. I open the addin and then open the workbook and the
    > macro executes now.
    >
    > ksr wrote:
    > > I added code to open the addin, but I can't get it to work. Is it
    > > sufficient to add code to open the addin or should I make a call to
    > > something else?
    > >
    > > Thankyou.
    > >
    > > ksr wrote:
    > > > Thankyou,
    > > > Can you give me some example code on how to open an addin? or how to
    > > > load as an addin?
    > > >
    > > > Tom Ogilvy wrote:
    > > > > Sure, in the same code that opens the workbook, open the addin as well.
    > > > >
    > > > > As an alternative, you can load it as an addin, but opening it should have
    > > > > the same effect.
    > > > >
    > > > > --
    > > > > Regards,
    > > > > Tom Ogilvy
    > > > >
    > > > >
    > > > > "ksr" wrote:
    > > > >
    > > > > > Thanks.
    > > > > > Is there any way I can have this macro execute when excel is started
    > > > > > programatically?
    > > > > >
    > > > > >
    > > > > > Tom Ogilvy wrote:
    > > > > > > I see your deeply engaged with Don in some heavy duty topics, but just for
    > > > > > > interest, Addins and files in the xlStart directory are not loaded when Excel
    > > > > > > is started programmatically.
    > > > > > >
    > > > > > > --
    > > > > > > Regards,
    > > > > > > Tom Ogilvy
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > > > "[email protected]" wrote:
    > > > > > >
    > > > > > > >
    > > > > > > > Don Guillett wrote:
    > > > > > > > > >>Application.EnableEvent(True)
    > > > > > > > > Application.EnableEventS=true
    > > > > > > > >
    > > > > > > > >
    > > > > > > > > Here is one I use with a double_click event to goto a workbook whose name is
    > > > > > > > > typed in a cell.
    > > > > > > > >
    > > > > > > > > Sub GetWorkbook()
    > > > > > > > > If ActiveCell.Value = "" Then Exit Sub
    > > > > > > > > workbookname = ActiveCell.Value
    > > > > > > > > On Error GoTo OpenWorkbook
    > > > > > > > > Windows(workbookname & ".xls").Activate
    > > > > > > > > Exit Sub
    > > > > > > > > OpenWorkbook:
    > > > > > > > > Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen
    > > > > > > > > End Sub
    > > > > > > > > --
    > > > > > > > > Don Guillett
    > > > > > > > > SalesAid Software
    > > > > > > > > [email protected]
    > > > > > > > > <[email protected]> wrote in message
    > > > > > > > > news:[email protected]...
    > > > > > > > > > Hello,
    > > > > > > > > >
    > > > > > > > > > I have an excel addin (.xla) file under excel startup folder (ie,
    > > > > > > > > > \office11\startup), where I have defined App_WorkbookActivate event.
    > > > > > > > > > This macro executes fine when I open the excel file from explorer. But
    > > > > > > > > > when I open the file from automation, it does not execute.
    > > > > > > > > > The code is as follows,
    > > > > > > > > >
    > > > > > > > > > Application.EnableEvent(True)
    > > > > > > > > > ActiveWorkbook = AllWorkbooks.Open("filename")
    > > > > > > > > > ActiveWorkbook.RunAutoMacros(3)
    > > > > > > > > >
    > > > > > > > > > Any suggestions would help!
    > > > > > > > > >
    > > > > > > > > > Thankyou.
    > > > > > > > > >
    > > > > > > >
    > > > > > > > Thanks for your reply.
    > > > > > > > The code looks similar, except for
    > > > > > > > Windows(workbookname & ".xls").Activate
    > > > > > > > What does the above line of code do?
    > > > > > > > I am writing in c++ and I am not sure what is the code equivalent to
    > > > > > > > the above in c++?
    > > > > > > > I understand Workbook activate is executed when workopen is opened.
    > > > > > > >
    > > > > > > >
    > > > > >
    > > > > >

    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1