Sort (in Excel) from code in MSProject

  • Thread starter Thread starter Peter Darmody
  • Start date Start date
P

Peter Darmody

I have written code in Microsoft Project which creates an
excel workbook and then creates a report in excel from
information in Project.
When I have finished the report I want to sort it on a
certain field, but I can't get the Sort to work.
I have had various errors but the latest is
"application or object defined error"

I have set up the code like this (remembering that this is
written in a module in Microsoft project)

- Check to see if excel is running with
Set MyXL = GetObject(, "Excel.Application")
and if this produces an error I start Excel with
Set MyXL = CreateObject("Excel.Application")

I then create a new workbook with

MyXL.Application.Workbooks.Add
outbook = MyXL.Application.ActiveWorkbook.Name

and then proceed to fill the report using:

With MyXL.Application.Workbooks(outbook).ActiveSheet
<fill report with data>

While still within the WITH statement I have tried
to sort the report with:

..Range("A1:L" & CStr(Rownum - 1)).Sort Key1:=Range("K2"),
Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1,
MatchCase:=False, Orientation:=xlTopToBottom

But it won't work.

Any suggestions??

Peter
 
try putting a period/full stop in front of the Range("K2")

Key1:=.Range("K2"),

perhaps project has a range object.

Also, do you have a reference set to the excel object library? If not, all
your constant values are essentially undefined/uninitialized variables with
a interpretation being a value of zero. You would need to put in the
appropriate numbers or create the reference.
 
AAAHHHhhh!!!
So simple!! (It worked)

Thanks Tom.

-----Original Message-----
try putting a period/full stop in front of the Range("K2")

Key1:=.Range("K2"),

perhaps project has a range object.

Also, do you have a reference set to the excel object library? If not, all
your constant values are essentially
undefined/uninitialized variables with
 
Back
Top