ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Unable to open worksheet when called through a function (https://www.excelbanter.com/excel-programming/394536-unable-open-worksheet-when-called-through-function.html)

zoddiax

Unable to open worksheet when called through a function
 
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


zoddiax

Simple Excel Problem
 
Please help me out with this Simple Excel Problem

"zoddiax" wrote:

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


Michael

Unable to open worksheet when called through a function
 
Try this:
Open a cmd prompt and type:

regsvr32 "%windir%\system32\cdosys.dll

Regards,

Michael Arch.

Please rate this answer



"zoddiax" wrote:

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


zoddiax

Unable to open worksheet when called through a function
 
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" wrote:

Try this:
Open a cmd prompt and type:

regsvr32 "%windir%\system32\cdosys.dll

Regards,

Michael Arch.

Please rate this answer



"zoddiax" wrote:

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



All times are GMT +1. The time now is 12:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com