R
RobV
I have a Project VBA macro that creates an Excel file. When I use Early
Binding, there’s no problem. (I use Early Binding because the macro is
distributed to PCs with different versions of Project, Excel, etc.) When I
switch to Late Binding, the Sort command raises a run-time error: "Object
required", and it points to "s.Range" as the problem. I use s.Range
elsewhere in the macro with no problem. Is there something special about
using Range with Sort? Here is the relevant code extract:
Dim XL As Object
Set XL = CreateObject("Excel.Application")
<error handling if Excel already open>
XL.Workbooks.Add
BookNam = XL.ActiveWorkbook.Name
Set s = XL.Workbooks(BookNam).Worksheets(1)
<other logic>
s.Range("A" & SelectionStartRow & ":" & "G" & SelectionEndRow).Select
Selection.Sort Key1:=s.Range("C1"), _
Order1:=xlAscending, Key2:=Range("E1"), _
Order2:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:= _
xlSortNormal
PS the xl-parameters have been DIM'd as constants.
Binding, there’s no problem. (I use Early Binding because the macro is
distributed to PCs with different versions of Project, Excel, etc.) When I
switch to Late Binding, the Sort command raises a run-time error: "Object
required", and it points to "s.Range" as the problem. I use s.Range
elsewhere in the macro with no problem. Is there something special about
using Range with Sort? Here is the relevant code extract:
Dim XL As Object
Set XL = CreateObject("Excel.Application")
<error handling if Excel already open>
XL.Workbooks.Add
BookNam = XL.ActiveWorkbook.Name
Set s = XL.Workbooks(BookNam).Worksheets(1)
<other logic>
s.Range("A" & SelectionStartRow & ":" & "G" & SelectionEndRow).Select
Selection.Sort Key1:=s.Range("C1"), _
Order1:=xlAscending, Key2:=Range("E1"), _
Order2:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:= _
xlSortNormal
PS the xl-parameters have been DIM'd as constants.