ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Weird error (https://www.excelbanter.com/excel-programming/360023-weird-error.html)

Adi[_3_]

Weird error
 
Hi
I am getting a error saying "?" for the following line:

Worksheet =(Worksheet)workbook.Worksheets.Add(Type.Missing,
Type.Missing,Type.Missing, Type.Missing);

does any one has an explanation to this, i mean how could an error have
no explaination and just show a "?" on ex.Message (Exception ex)

Please, help me out.. i don't know what to do!

Thanks


[email protected]

Weird error
 
Hi
Worksheet and workbook are not good variable names as they are objects
in Excel VBA. If you want to create a new worksheet in your workbook
try:

Set myWorkSheet = myWorkBook.WorkSheets.Add

where you might have done
Set myWorkBook = Application.Workbooks("Tester")
or
Set myWorkBook = ActiveWorkBook

look at the parameters in the Add method for control over where it goes
in the workbook.

regards
Paul


Tom Ogilvy

Weird error
 
Your talking about VBA and the OP is talking about .NET.

--
Regards,
Tom Ogilvy


" wrote:

Hi
Worksheet and workbook are not good variable names as they are objects
in Excel VBA. If you want to create a new worksheet in your workbook
try:

Set myWorkSheet = myWorkBook.WorkSheets.Add

where you might have done
Set myWorkBook = Application.Workbooks("Tester")
or
Set myWorkBook = ActiveWorkBook

look at the parameters in the Add method for control over where it goes
in the workbook.

regards
Paul



Adi[_3_]

Weird error
 
hi,
that was just example line so that it would be easy to understand
i have thought not used that same names..
one more thing..
i am trying to develop excell addin through c#

now when i try n create a worksheet in active workbook it gives me this
error in that line which has ex.message as "?" nothing else..
Mind you this error is not a fixed one, i mean this error is not always
occuring.. it many times works fine and some times gives the error..(i
know this is absurd.. but?)


Adi[_3_]

Weird error
 
hi Tom,
U r absolutely right!
And plzz if you know some thing about this help me.. i am stuck
Thanks


Tom Ogilvy

Weird error
 
I really don't know anything about C# and .NET, but shouldn't it be something
like:
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet oSheet

.. . .

oSheet = (Excel._Worksheet) oWB.Worksheets.Add(Missing.Value,
Missing.Value, Missing.Value, Missing.Value);

Missing.Value instead of Type.Missing

--
Regards,
Tom Ogilvy



"Adi" wrote:

hi Tom,
U r absolutely right!
And plzz if you know some thing about this help me.. i am stuck
Thanks



Adi[_3_]

Weird error
 
Thanks Tom but as far as I know Missing.Value and Type.Missing gives
the same result. If there are any differences that you know, please let
me know too. :)



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

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