Unable to open worksheet when called through a function

G

Guest

I am trying to open worksheet but it gives me the following error. This error
dosent occur every time. Its random. That's why I have put my code in try
block.

System.Runtime.InteropServices.COMException (0x8002801D): Library not
registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))
at Microsoft.Office.Interop.Excel.Sheets.get__Default(Object Index)

Following is my code snippet

private void PasteData(string sSheet)
{
try
{
/* Open the corresponding sheet in the WorkSheet */
xlSheetScript =
(Excel.Worksheet)xlBookScript.Worksheets[sSheet];

/* Find the last row in that sheet */
for (iCount = 400; iCount > 0; iCount--)
{
xlRange = (Excel.Range)xlSheetScript.Cells[iCount, 2];
if (xlRange.Value2 != null)
{
break;
}
}

Any help will be greatly appreciated.
Thanks
 
G

Guest

Try this:
Open a cmd prompt and type:

regsvr32 "%windir%\system32\cdosys.dll

Regards,

Michael Arch.

Please rate this answer
 
G

Guest

Hi Michael

Thanks for your answer but I am still getting the same error and its random.
I get it 1 time for every 300 times or 400 times I run the code

Michael said:
Try this:
Open a cmd prompt and type:

regsvr32 "%windir%\system32\cdosys.dll

Regards,

Michael Arch.

Please rate this answer



zoddiax said:
I am trying to open worksheet but it gives me the following error. This error
dosent occur every time. Its random. That's why I have put my code in try
block.

System.Runtime.InteropServices.COMException (0x8002801D): Library not
registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))
at Microsoft.Office.Interop.Excel.Sheets.get__Default(Object Index)

Following is my code snippet

private void PasteData(string sSheet)
{
try
{
/* Open the corresponding sheet in the WorkSheet */
xlSheetScript =
(Excel.Worksheet)xlBookScript.Worksheets[sSheet];

/* Find the last row in that sheet */
for (iCount = 400; iCount > 0; iCount--)
{
xlRange = (Excel.Range)xlSheetScript.Cells[iCount, 2];
if (xlRange.Value2 != null)
{
break;
}
}

Any help will be greatly appreciated.
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top