+ Reply to Thread
Results 1 to 12 of 12

Problem using VBA for the Networkdays function

  1. #1
    jamesp@premiercs.co.uk
    Guest

    Problem using VBA for the Networkdays function

    I am using VBA in MS project to enter information into Excel 2003. It
    creates an instance and enters various dates. However if I put the
    Newworkdays function into a cell (e.g. xlApp.range("D6").value =
    "=networkdays(rc[-3],rc[-2])" where D4 and D5 are recognised dates I get the
    #NAME? error message. The Add-ins for the Analysis toolpak have been ticked.


    I tried running code to turn the analysis toolpak off and then on
    programatically but still the same error message

    Any ideas how this can be fixed?

    Many thanks

    James

  2. #2
    Niek Otten
    Guest

    Re: Problem using VBA for the Networkdays function

    Hi James,

    Range("D6").FormulaR1C1 = "=networkdays(rc[-3],rc[-2])"

    --
    Kind regards,

    Niek Otten
    Microsoft MVP - Excel

    "jamesp@premiercs.co.uk" <jamesppremiercscouk@discussions.microsoft.com> wrote in message
    news:5D68B2EC-A845-4344-85F5-701A6963E6D8@microsoft.com...
    |I am using VBA in MS project to enter information into Excel 2003. It
    | creates an instance and enters various dates. However if I put the
    | Newworkdays function into a cell (e.g. xlApp.range("D6").value =
    | "=networkdays(rc[-3],rc[-2])" where D4 and D5 are recognised dates I get the
    | #NAME? error message. The Add-ins for the Analysis toolpak have been ticked.
    |
    |
    | I tried running code to turn the analysis toolpak off and then on
    | programatically but still the same error message
    |
    | Any ideas how this can be fixed?
    |
    | Many thanks
    |
    | James



  3. #3
    jamesp@premiercs.co.uk
    Guest

    RE: Problem using VBA for the Networkdays function

    Sorry Niek doesn't work. In my experience .value and .formular1c1 work the
    same

    James

    "jamesp@premiercs.co.uk" wrote:

    > I am using VBA in MS project to enter information into Excel 2003. It
    > creates an instance and enters various dates. However if I put the
    > Newworkdays function into a cell (e.g. xlApp.range("D6").value =
    > "=networkdays(rc[-3],rc[-2])" where D4 and D5 are recognised dates I get the
    > #NAME? error message. The Add-ins for the Analysis toolpak have been ticked.
    >
    >
    > I tried running code to turn the analysis toolpak off and then on
    > programatically but still the same error message
    >
    > Any ideas how this can be fixed?
    >
    > Many thanks
    >
    > James


  4. #4
    Niek Otten
    Guest

    Re: Problem using VBA for the Networkdays function

    Be aware that your formula is not referring to D4 and D5, but to A6 and B6. Are any of them #NAME?
    I assume that you have Analysis Toolpak ticked in your worksheet Add-ins menu, not (just) VBA

    --
    Kind regards,

    Niek Otten
    Microsoft MVP - Excel

    "jamesp@premiercs.co.uk" <jamesppremiercscouk@discussions.microsoft.com> wrote in message
    news:01147221-32FF-47E3-B2D5-6F30A2B131FD@microsoft.com...
    | Sorry Niek doesn't work. In my experience .value and .formular1c1 work the
    | same
    |
    | James
    |
    | "jamesp@premiercs.co.uk" wrote:
    |
    | > I am using VBA in MS project to enter information into Excel 2003. It
    | > creates an instance and enters various dates. However if I put the
    | > Newworkdays function into a cell (e.g. xlApp.range("D6").value =
    | > "=networkdays(rc[-3],rc[-2])" where D4 and D5 are recognised dates I get the
    | > #NAME? error message. The Add-ins for the Analysis toolpak have been ticked.
    | >
    | >
    | > I tried running code to turn the analysis toolpak off and then on
    | > programatically but still the same error message
    | >
    | > Any ideas how this can be fixed?
    | >
    | > Many thanks
    | >
    | > James



  5. #5
    jamesp@premiercs.co.uk
    Guest

    Re: Problem using VBA for the Networkdays function

    it is D4 and D5. More importantly the function name is not in capitals
    implying that XL can't see the function name. The Analysis toolpak has been
    ticked in the Add-ins

    Try it creating a simple macro in Word - I can give you the code if you want


    "Niek Otten" wrote:

    > Be aware that your formula is not referring to D4 and D5, but to A6 and B6. Are any of them #NAME?
    > I assume that you have Analysis Toolpak ticked in your worksheet Add-ins menu, not (just) VBA
    >
    > --
    > Kind regards,
    >
    > Niek Otten
    > Microsoft MVP - Excel
    >
    > "jamesp@premiercs.co.uk" <jamesppremiercscouk@discussions.microsoft.com> wrote in message
    > news:01147221-32FF-47E3-B2D5-6F30A2B131FD@microsoft.com...
    > | Sorry Niek doesn't work. In my experience .value and .formular1c1 work the
    > | same
    > |
    > | James
    > |
    > | "jamesp@premiercs.co.uk" wrote:
    > |
    > | > I am using VBA in MS project to enter information into Excel 2003. It
    > | > creates an instance and enters various dates. However if I put the
    > | > Newworkdays function into a cell (e.g. xlApp.range("D6").value =
    > | > "=networkdays(rc[-3],rc[-2])" where D4 and D5 are recognised dates I get the
    > | > #NAME? error message. The Add-ins for the Analysis toolpak have been ticked.
    > | >
    > | >
    > | > I tried running code to turn the analysis toolpak off and then on
    > | > programatically but still the same error message
    > | >
    > | > Any ideas how this can be fixed?
    > | >
    > | > Many thanks
    > | >
    > | > James
    >
    >
    >


  6. #6
    Bob Phillips
    Guest

    Re: Problem using VBA for the Networkdays function

    James,

    When you use Excel via automation, the addins do not get loaded, so you get
    the error.

    Force the load like so


    xlApp.AddIns("Analysis ToolPak").Installed = False
    xlApp.AddIns("Analysis ToolPak").Installed = True
    xlApp.Range("D6").Value = "=networkdays(rc[-3],rc[-2])"

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "jamesp@premiercs.co.uk" <jamesppremiercscouk@discussions.microsoft.com>
    wrote in message news:4C8ECC36-2BEF-48A2-8509-142531756B69@microsoft.com...
    > it is D4 and D5. More importantly the function name is not in capitals
    > implying that XL can't see the function name. The Analysis toolpak has

    been
    > ticked in the Add-ins
    >
    > Try it creating a simple macro in Word - I can give you the code if you

    want
    >
    >
    > "Niek Otten" wrote:
    >
    > > Be aware that your formula is not referring to D4 and D5, but to A6 and

    B6. Are any of them #NAME?
    > > I assume that you have Analysis Toolpak ticked in your worksheet Add-ins

    menu, not (just) VBA
    > >
    > > --
    > > Kind regards,
    > >
    > > Niek Otten
    > > Microsoft MVP - Excel
    > >
    > > "jamesp@premiercs.co.uk" <jamesppremiercscouk@discussions.microsoft.com>

    wrote in message
    > > news:01147221-32FF-47E3-B2D5-6F30A2B131FD@microsoft.com...
    > > | Sorry Niek doesn't work. In my experience .value and .formular1c1

    work the
    > > | same
    > > |
    > > | James
    > > |
    > > | "jamesp@premiercs.co.uk" wrote:
    > > |
    > > | > I am using VBA in MS project to enter information into Excel 2003.

    It
    > > | > creates an instance and enters various dates. However if I put the
    > > | > Newworkdays function into a cell (e.g. xlApp.range("D6").value =
    > > | > "=networkdays(rc[-3],rc[-2])" where D4 and D5 are recognised dates I

    get the
    > > | > #NAME? error message. The Add-ins for the Analysis toolpak have

    been ticked.
    > > | >
    > > | >
    > > | > I tried running code to turn the analysis toolpak off and then on
    > > | > programatically but still the same error message
    > > | >
    > > | > Any ideas how this can be fixed?
    > > | >
    > > | > Many thanks
    > > | >
    > > | > James
    > >
    > >
    > >




  7. #7
    Niek Otten
    Guest

    Re: Problem using VBA for the Networkdays function

    Hi James,

    And after you've sorted that out, check the cell references in your formula in the worksheet; it IS A6 and B6 (Columns -3 and -2,
    not Rows)

    --
    Kind regards,

    Niek Otten
    Microsoft MVP - Excel

    "Bob Phillips" <bob.NGs@somewhere.com> wrote in message news:uQSq4n7vGHA.4444@TK2MSFTNGP05.phx.gbl...
    | James,
    |
    | When you use Excel via automation, the addins do not get loaded, so you get
    | the error.
    |
    | Force the load like so
    |
    |
    | xlApp.AddIns("Analysis ToolPak").Installed = False
    | xlApp.AddIns("Analysis ToolPak").Installed = True
    | xlApp.Range("D6").Value = "=networkdays(rc[-3],rc[-2])"
    |
    | --
    | HTH
    |
    | Bob Phillips
    |
    | (replace somewhere in email address with gmail if mailing direct)
    |
    | "jamesp@premiercs.co.uk" <jamesppremiercscouk@discussions.microsoft.com>
    | wrote in message news:4C8ECC36-2BEF-48A2-8509-142531756B69@microsoft.com...
    | > it is D4 and D5. More importantly the function name is not in capitals
    | > implying that XL can't see the function name. The Analysis toolpak has
    | been
    | > ticked in the Add-ins
    | >
    | > Try it creating a simple macro in Word - I can give you the code if you
    | want
    | >
    | >
    | > "Niek Otten" wrote:
    | >
    | > > Be aware that your formula is not referring to D4 and D5, but to A6 and
    | B6. Are any of them #NAME?
    | > > I assume that you have Analysis Toolpak ticked in your worksheet Add-ins
    | menu, not (just) VBA
    | > >
    | > > --
    | > > Kind regards,
    | > >
    | > > Niek Otten
    | > > Microsoft MVP - Excel
    | > >
    | > > "jamesp@premiercs.co.uk" <jamesppremiercscouk@discussions.microsoft.com>
    | wrote in message
    | > > news:01147221-32FF-47E3-B2D5-6F30A2B131FD@microsoft.com...
    | > > | Sorry Niek doesn't work. In my experience .value and .formular1c1
    | work the
    | > > | same
    | > > |
    | > > | James
    | > > |
    | > > | "jamesp@premiercs.co.uk" wrote:
    | > > |
    | > > | > I am using VBA in MS project to enter information into Excel 2003.
    | It
    | > > | > creates an instance and enters various dates. However if I put the
    | > > | > Newworkdays function into a cell (e.g. xlApp.range("D6").value =
    | > > | > "=networkdays(rc[-3],rc[-2])" where D4 and D5 are recognised dates I
    | get the
    | > > | > #NAME? error message. The Add-ins for the Analysis toolpak have
    | been ticked.
    | > > | >
    | > > | >
    | > > | > I tried running code to turn the analysis toolpak off and then on
    | > > | > programatically but still the same error message
    | > > | >
    | > > | > Any ideas how this can be fixed?
    | > > | >
    | > > | > Many thanks
    | > > | >
    | > > | > James
    | > >
    | > >
    | > >
    |
    |



  8. #8
    Bob Phillips
    Guest

    Re: Problem using VBA for the Networkdays function

    I agree with Niek, it came out as A6,B6 in all my tests.

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "Niek Otten" <nicolaus@xs4all.nl> wrote in message
    news:%238Lqiv7vGHA.3392@TK2MSFTNGP04.phx.gbl...
    > Hi James,
    >
    > And after you've sorted that out, check the cell references in your

    formula in the worksheet; it IS A6 and B6 (Columns -3 and -2,
    > not Rows)
    >
    > --
    > Kind regards,
    >
    > Niek Otten
    > Microsoft MVP - Excel
    >
    > "Bob Phillips" <bob.NGs@somewhere.com> wrote in message

    news:uQSq4n7vGHA.4444@TK2MSFTNGP05.phx.gbl...
    > | James,
    > |
    > | When you use Excel via automation, the addins do not get loaded, so you

    get
    > | the error.
    > |
    > | Force the load like so
    > |
    > |
    > | xlApp.AddIns("Analysis ToolPak").Installed = False
    > | xlApp.AddIns("Analysis ToolPak").Installed = True
    > | xlApp.Range("D6").Value = "=networkdays(rc[-3],rc[-2])"
    > |
    > | --
    > | HTH
    > |
    > | Bob Phillips
    > |
    > | (replace somewhere in email address with gmail if mailing direct)
    > |
    > | "jamesp@premiercs.co.uk" <jamesppremiercscouk@discussions.microsoft.com>
    > | wrote in message

    news:4C8ECC36-2BEF-48A2-8509-142531756B69@microsoft.com...
    > | > it is D4 and D5. More importantly the function name is not in

    capitals
    > | > implying that XL can't see the function name. The Analysis toolpak

    has
    > | been
    > | > ticked in the Add-ins
    > | >
    > | > Try it creating a simple macro in Word - I can give you the code if

    you
    > | want
    > | >
    > | >
    > | > "Niek Otten" wrote:
    > | >
    > | > > Be aware that your formula is not referring to D4 and D5, but to A6

    and
    > | B6. Are any of them #NAME?
    > | > > I assume that you have Analysis Toolpak ticked in your worksheet

    Add-ins
    > | menu, not (just) VBA
    > | > >
    > | > > --
    > | > > Kind regards,
    > | > >
    > | > > Niek Otten
    > | > > Microsoft MVP - Excel
    > | > >
    > | > > "jamesp@premiercs.co.uk"

    <jamesppremiercscouk@discussions.microsoft.com>
    > | wrote in message
    > | > > news:01147221-32FF-47E3-B2D5-6F30A2B131FD@microsoft.com...
    > | > > | Sorry Niek doesn't work. In my experience .value and .formular1c1
    > | work the
    > | > > | same
    > | > > |
    > | > > | James
    > | > > |
    > | > > | "jamesp@premiercs.co.uk" wrote:
    > | > > |
    > | > > | > I am using VBA in MS project to enter information into Excel

    2003.
    > | It
    > | > > | > creates an instance and enters various dates. However if I put

    the
    > | > > | > Newworkdays function into a cell (e.g. xlApp.range("D6").value =
    > | > > | > "=networkdays(rc[-3],rc[-2])" where D4 and D5 are recognised

    dates I
    > | get the
    > | > > | > #NAME? error message. The Add-ins for the Analysis toolpak have
    > | been ticked.
    > | > > | >
    > | > > | >
    > | > > | > I tried running code to turn the analysis toolpak off and then

    on
    > | > > | > programatically but still the same error message
    > | > > | >
    > | > > | > Any ideas how this can be fixed?
    > | > > | >
    > | > > | > Many thanks
    > | > > | >
    > | > > | > James
    > | > >
    > | > >
    > | > >
    > |
    > |
    >
    >




  9. #9
    jamesp@premiercs.co.uk
    Guest

    Re: Problem using VBA for the Networkdays function

    Bob

    The original formula that I had has square brackets which means that it's a
    relative to the D6. In this case A6 and B6.
    xlApp.range("D6").value ="=networkdays(rc[-3],rc[-2])"

    I already tried adding code to clear the addins and then restart them again
    but no use.

    I think that when you open a new instance of Excel from another MS App the
    Addins do not get loaded. In this case I am using MS Project to load Excel.
    I have just noticed that when I type in MyApp.worksheetfunction then press
    the '.' button for a list of methods/property parameters (?) it doesn't list
    networkdays.

    Does this make sense and if so can you help?

    Many thanks

    James


    "Bob Phillips" wrote:

    > I agree with Niek, it came out as A6,B6 in all my tests.
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (replace somewhere in email address with gmail if mailing direct)
    >
    > "Niek Otten" <nicolaus@xs4all.nl> wrote in message
    > news:%238Lqiv7vGHA.3392@TK2MSFTNGP04.phx.gbl...
    > > Hi James,
    > >
    > > And after you've sorted that out, check the cell references in your

    > formula in the worksheet; it IS A6 and B6 (Columns -3 and -2,
    > > not Rows)
    > >
    > > --
    > > Kind regards,
    > >
    > > Niek Otten
    > > Microsoft MVP - Excel
    > >
    > > "Bob Phillips" <bob.NGs@somewhere.com> wrote in message

    > news:uQSq4n7vGHA.4444@TK2MSFTNGP05.phx.gbl...
    > > | James,
    > > |
    > > | When you use Excel via automation, the addins do not get loaded, so you

    > get
    > > | the error.
    > > |
    > > | Force the load like so
    > > |
    > > |
    > > | xlApp.AddIns("Analysis ToolPak").Installed = False
    > > | xlApp.AddIns("Analysis ToolPak").Installed = True
    > > | xlApp.Range("D6").Value = "=networkdays(rc[-3],rc[-2])"
    > > |
    > > | --
    > > | HTH
    > > |
    > > | Bob Phillips
    > > |
    > > | (replace somewhere in email address with gmail if mailing direct)
    > > |
    > > | "jamesp@premiercs.co.uk" <jamesppremiercscouk@discussions.microsoft.com>
    > > | wrote in message

    > news:4C8ECC36-2BEF-48A2-8509-142531756B69@microsoft.com...
    > > | > it is D4 and D5. More importantly the function name is not in

    > capitals
    > > | > implying that XL can't see the function name. The Analysis toolpak

    > has
    > > | been
    > > | > ticked in the Add-ins
    > > | >
    > > | > Try it creating a simple macro in Word - I can give you the code if

    > you
    > > | want
    > > | >
    > > | >
    > > | > "Niek Otten" wrote:
    > > | >
    > > | > > Be aware that your formula is not referring to D4 and D5, but to A6

    > and
    > > | B6. Are any of them #NAME?
    > > | > > I assume that you have Analysis Toolpak ticked in your worksheet

    > Add-ins
    > > | menu, not (just) VBA
    > > | > >
    > > | > > --
    > > | > > Kind regards,
    > > | > >
    > > | > > Niek Otten
    > > | > > Microsoft MVP - Excel
    > > | > >
    > > | > > "jamesp@premiercs.co.uk"

    > <jamesppremiercscouk@discussions.microsoft.com>
    > > | wrote in message
    > > | > > news:01147221-32FF-47E3-B2D5-6F30A2B131FD@microsoft.com...
    > > | > > | Sorry Niek doesn't work. In my experience .value and .formular1c1
    > > | work the
    > > | > > | same
    > > | > > |
    > > | > > | James
    > > | > > |
    > > | > > | "jamesp@premiercs.co.uk" wrote:
    > > | > > |
    > > | > > | > I am using VBA in MS project to enter information into Excel

    > 2003.
    > > | It
    > > | > > | > creates an instance and enters various dates. However if I put

    > the
    > > | > > | > Newworkdays function into a cell (e.g. xlApp.range("D6").value =
    > > | > > | > "=networkdays(rc[-3],rc[-2])" where D4 and D5 are recognised

    > dates I
    > > | get the
    > > | > > | > #NAME? error message. The Add-ins for the Analysis toolpak have
    > > | been ticked.
    > > | > > | >
    > > | > > | >
    > > | > > | > I tried running code to turn the analysis toolpak off and then

    > on
    > > | > > | > programatically but still the same error message
    > > | > > | >
    > > | > > | > Any ideas how this can be fixed?
    > > | > > | >
    > > | > > | > Many thanks
    > > | > > | >
    > > | > > | > James
    > > | > >
    > > | > >
    > > | > >
    > > |
    > > |
    > >
    > >

    >
    >
    >


  10. #10
    Bob Phillips
    Guest

    Re: Problem using VBA for the Networkdays function



    "jamesp@premiercs.co.uk" <jamesppremiercscouk@discussions.microsoft.com>
    wrote in message news:724AB477-54FB-4FA5-8168-84F9F1757ED2@microsoft.com...
    >
    > I think that when you open a new instance of Excel from another MS App the
    > Addins do not get loaded.


    That ius exactly waht I said, which is why I suggested forcing the load. I
    was able to reproduce your error, not from MSProject but from automation,
    and by installing the addin, it worked fine.

    > In this case I am using MS Project to load Excel.
    > I have just noticed that when I type in MyApp.worksheetfunction then press
    > the '.' button for a list of methods/property parameters (?) it doesn't

    list
    > networkdays.


    Networkdays is not a worksheetfunction, it is part of the Analysis Toolpak,
    so you won't see it, even from within excl



  11. #11
    jamesp@premiercs.co.uk
    Guest

    Re: Problem using VBA for the Networkdays function

    Bob

    I thought I had already closed and added the Add-ins but I somehow screwed
    it up. Problem fixed. Sorry for being a arsey on the last email - long day!

    Cheers

    James

    "Bob Phillips" wrote:

    >
    >
    > "jamesp@premiercs.co.uk" <jamesppremiercscouk@discussions.microsoft.com>
    > wrote in message news:724AB477-54FB-4FA5-8168-84F9F1757ED2@microsoft.com...
    > >
    > > I think that when you open a new instance of Excel from another MS App the
    > > Addins do not get loaded.

    >
    > That ius exactly waht I said, which is why I suggested forcing the load. I
    > was able to reproduce your error, not from MSProject but from automation,
    > and by installing the addin, it worked fine.
    >
    > > In this case I am using MS Project to load Excel.
    > > I have just noticed that when I type in MyApp.worksheetfunction then press
    > > the '.' button for a list of methods/property parameters (?) it doesn't

    > list
    > > networkdays.

    >
    > Networkdays is not a worksheetfunction, it is part of the Analysis Toolpak,
    > so you won't see it, even from within excl
    >
    >
    >


  12. #12
    Bob Phillips
    Guest

    Re: Problem using VBA for the Networkdays function

    Well, at least you are sorted now.

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "jamesp@premiercs.co.uk" <jamesppremiercscouk@discussions.microsoft.com>
    wrote in message news:B2D65AF2-BA14-4DCB-994E-E9C6D26653F4@microsoft.com...
    > Bob
    >
    > I thought I had already closed and added the Add-ins but I somehow screwed
    > it up. Problem fixed. Sorry for being a arsey on the last email - long

    day!
    >
    > Cheers
    >
    > James
    >
    > "Bob Phillips" wrote:
    >
    > >
    > >
    > > "jamesp@premiercs.co.uk" <jamesppremiercscouk@discussions.microsoft.com>
    > > wrote in message

    news:724AB477-54FB-4FA5-8168-84F9F1757ED2@microsoft.com...
    > > >
    > > > I think that when you open a new instance of Excel from another MS App

    the
    > > > Addins do not get loaded.

    > >
    > > That ius exactly waht I said, which is why I suggested forcing the load.

    I
    > > was able to reproduce your error, not from MSProject but from

    automation,
    > > and by installing the addin, it worked fine.
    > >
    > > > In this case I am using MS Project to load Excel.
    > > > I have just noticed that when I type in MyApp.worksheetfunction then

    press
    > > > the '.' button for a list of methods/property parameters (?) it

    doesn't
    > > list
    > > > networkdays.

    > >
    > > Networkdays is not a worksheetfunction, it is part of the Analysis

    Toolpak,
    > > so you won't see it, even from within excl
    > >
    > >
    > >




+ 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