Run-time error using late binding

D

DaBookshah

Hi there. I previously created a different topic about this, but its
dissapeared in the mean-time, and I didnt explain myself very well
anyway it seems.

Basically I have a program written in VB, using Visual Basic for
Applications with Excel. Now this program works fine with Excel 2003,
but I get a run-time error with Excel 2000 relating to the signature of
the Range.Sort method. I am not using any of the last 3 parameters,
which were only added in 2003. According to what I was told previously,
the dependency is somehow "recompiled" or something behind the scenes,
so that if my program runs on a computer with excel 2000, it realises
this and uses that. But that doesn't help explain my error.

I am using late-binding for this, and I can see from the error message
that my program is still trying to call Range.Sort on Excel 2000 with
the parameters DataSortOption 1,2 and 3, which dont exist in 2000. I
have no idea how to fix this, but i think it might be related to the
use of late-binding?

************** Exception Text **************
System.Reflection.TargetParameterCountException: Number of parameters
specified does not match the expected number.
at System.RuntimeType.ForwardCallToInvokeMember(String memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at Microsoft.Office.Interop.Excel.Range.Sort(Object Key1,
XlSortOrder Order1, Object Key2, Object Type, XlSortOrder Order2,
Object Key3, XlSortOrder Order3, XlYesNoGuess Header, Object
OrderCustom, Object MatchCase, XlSortOrientation Orientation,
XlSortMethod SortMethod, XlSortDataOption DataOption1, XlSortDataOption
DataOption2, XlSortDataOption DataOption3)
at exceltest.Form1.StartExcel(DateTime StartDate, DateTime EndDate,
Worksheet& currentWorkSheet, Connection& Connection)
at exceltest.Form1.GenerateButton_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
exceltest
Assembly Version: 1.0.2359.22364
Win32 Version: 1.0.2359.22364
CodeBase:
file:///C:/Program%20Files/InTime%20Extractor/exceltest.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
ADODB
Assembly Version: 7.0.3300.0
Win32 Version: 7.10.3077
CodeBase: file:///C:/Program%20Files/InTime%20Extractor/ADODB.DLL
----------------------------------------
Microsoft.Office.Interop.Excel
Assembly Version: 11.0.0.0
Win32 Version: 11.0.5530
CodeBase:
file:///C:/Program%20Files/InTime%20Extractor/Microsoft.Office.Interop.Excel.DLL
 
R

RB Smissaert

Better to post the code that caused the error than all that error stuff.

RBS

DaBookshah said:
Hi there. I previously created a different topic about this, but its
dissapeared in the mean-time, and I didnt explain myself very well
anyway it seems.

Basically I have a program written in VB, using Visual Basic for
Applications with Excel. Now this program works fine with Excel 2003,
but I get a run-time error with Excel 2000 relating to the signature of
the Range.Sort method. I am not using any of the last 3 parameters,
which were only added in 2003. According to what I was told previously,
the dependency is somehow "recompiled" or something behind the scenes,
so that if my program runs on a computer with excel 2000, it realises
this and uses that. But that doesn't help explain my error.

I am using late-binding for this, and I can see from the error message
that my program is still trying to call Range.Sort on Excel 2000 with
the parameters DataSortOption 1,2 and 3, which dont exist in 2000. I
have no idea how to fix this, but i think it might be related to the
use of late-binding?

************** Exception Text **************
System.Reflection.TargetParameterCountException: Number of parameters
specified does not match the expected number.
at System.RuntimeType.ForwardCallToInvokeMember(String memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at Microsoft.Office.Interop.Excel.Range.Sort(Object Key1,
XlSortOrder Order1, Object Key2, Object Type, XlSortOrder Order2,
Object Key3, XlSortOrder Order3, XlYesNoGuess Header, Object
OrderCustom, Object MatchCase, XlSortOrientation Orientation,
XlSortMethod SortMethod, XlSortDataOption DataOption1, XlSortDataOption
DataOption2, XlSortDataOption DataOption3)
at exceltest.Form1.StartExcel(DateTime StartDate, DateTime EndDate,
Worksheet& currentWorkSheet, Connection& Connection)
at exceltest.Form1.GenerateButton_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
exceltest
Assembly Version: 1.0.2359.22364
Win32 Version: 1.0.2359.22364
CodeBase:
file:///C:/Program%20Files/InTime%20Extractor/exceltest.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
ADODB
Assembly Version: 7.0.3300.0
Win32 Version: 7.10.3077
CodeBase: file:///C:/Program%20Files/InTime%20Extractor/ADODB.DLL
----------------------------------------
Microsoft.Office.Interop.Excel
Assembly Version: 11.0.0.0
Win32 Version: 11.0.5530
CodeBase:
file:///C:/Program%20Files/InTime%20Extractor/Microsoft.Office.Interop.Excel.DLL
 
D

DaBookshah

Ok. Thought someone might be able to make something out of the versions
on those "assemblies". But anyway.
Offending line seems to be:


With currentWorkSheet

.Range(.Cells(4, 1),
..Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell)).Sort(.Cells(4,
1), Excel.XlSortOrder.xlAscending, , , , , , Excel.XlYesNoGuess.xlNo,
1, False, Excel.XlSortOrientation.xlSortColumns)

End With
 
R

RB Smissaert

That doesn't look very normal to me.
How about record your sort in a macro and post that or
explain what sort you want to do?

RBS
 
G

Guest

This worked fine for me. I removed the "(" right after ".Sort" and the ")"
at the end. Some methods in Excel are funny about enclosing arguments in (
). Some methods require the arguments in ( ) if part of an expression,
otherwise the ( ) are excluded.


With currentWorkSheet

..Range(.Cells(4, 1), _
.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell)).Sort .Cells(4, _
1), Excel.XlSortOrder.xlAscending, , , , , , Excel.XlYesNoGuess.xlNo, _
1, False, Excel.XlSortOrientation.xlSortColumns
End With
 
D

DaBookshah

Nope. Doesn't work for me (In visual studio 2005). Says "End of
Statement Expected"
 
B

bart.smissaert

Only now it becomes clear that your code doesn't run from Excel VBA!
You did say VB, but many posters say that when they mean VBA.
You will need to post the whole procedure, not just the sort statement.

RBS
 

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