Error. Export template excel to NAS in NAV 2013R2

snupysnupy Member Posts: 11
Hi Everyone,

Can you please!

What am I doing wrong?

ExcelBuf.OpenBook_NAS2(FileName); - GOOD


Error in the function ExcelBuf.OpenSheet_NAS2("Template Sheet Name");

OpenSheet_NAS2(SheetName : Text[30])

i := 1;

EndOfLoop := XlWrkBkRTC.Worksheets.Count;
ERROR
A call to System.__ComObject.get_Count failed with this message: The type of one or more arguments does not match the method's parameter type.

WHILE (i <= EndOfLoop) AND (NOT Found) DO BEGIN

XlWrkShtRTC := XlWrkBkRTC.Worksheets.Item(i);
ERROR
A call to System.__ComObject.get_Item failed with this message: The type of one or more arguments does not match the method's parameter type.

IF SheetName = XlWrkShtRTC.Name THEN
Found := TRUE;
i := i + 1;
END;
IF Found THEN
XlWrkShtRTC := XlWrkBkRTC.Worksheets.Item(SheetName)
ELSE
ErrorExcelProcessing(STRSUBSTNO(WorksheetNotFoundErr,SheetName));

Help me, please!!!

Answers

  • KishormKishorm Member Posts: 921
    Refactoring the code might help, i.e. instead of...
    EndOfLoop := XlWrkBkRTC.Worksheets.Count;
    
    ...change it to...
    XlWrkShtsRTC := XlWrkBkRTC.Worksheets;
    EndOfLoop := XlWrkShtsRTC.Count;
    
    ...obviously you'll need a new variable for XlWrkShtsRTC to hold the Excel Worksheets (plural)
  • snupysnupy Member Posts: 11
    Kishorm wrote: »
    Refactoring the code might help, i.e. instead of...
    EndOfLoop := XlWrkBkRTC.Worksheets.Count;
    
    ...change it to...
    XlWrkShtsRTC := XlWrkBkRTC.Worksheets;
    EndOfLoop := XlWrkShtsRTC.Count;
    
    ...obviously you'll need a new variable for XlWrkShtsRTC to hold the Excel Worksheets (plural)

    Kishorm

    I Wrote

    i := 1;
    //EndOfLoop := XlWrkBkRTC.Worksheets.Count;

    XlWrkShtsRTC := XlWrkBkRTC.Worksheets;
    EndOfLoop := XlWrkShtsRTC.Count;

    new variable XlWrkShtsRTC = Microsoft.Office.Interop.Excel.Worksheets.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

    New Error
    Message: System.__ComObject.Count: Object does not match target type.
  • KishormKishorm Member Posts: 921
    Hmmm, I'm not sure you're going to have much luck with this, I found the following post...

    forum.mibuso.com/discussion/62541/excel-interop-runonclient-no
  • archer89archer89 Member Posts: 337
    Check If all dotnet variables have set same value for property runonclient. All false or all true. If Run trough nas then all false.
    best regards
    Franz Kalchmair, MVP
    Alias: Jonathan Archer

    please like / agree / verify my answer, if it was helpful for you. thx.
    Blog: http://moxie4nav.wordpress.com/
  • snupysnupy Member Posts: 11
    archer89 wrote: »
    Check If all dotnet variables have set same value for property runonclient. All false or all true. If Run trough nas then all false.

    All dotnet variables have runonclient = no
  • snupysnupy Member Posts: 11
    Kishorm wrote: »
    Hmmm, I'm not sure you're going to have much luck with this, I found the following post...

    forum.mibuso.com/discussion/62541/excel-interop-runonclient-no

    Thanks for the info.
    I have installed a language pack, but the error remained.

    It is a horror ((((
Sign In or Register to comment.