Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Problem with VBA macro running inside VB

I have created a VB6 program which uses some Excel automation to generate an
Excel formatted document from a CSV file.

Inside Excel VBA running in Excel 2003, I have the following

Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Key2:=Range("F2") _
, Order2:=xlAscending, Key3:=Range("A2"), Order3:=xlAscending,
Header:=xlYes, OrderCustom:=1, MatchCase:=False _
, Orientation:=xlTopToBottom

however in the VB applciation i have

Dim xl as Excel.Application
Set xl = New Excel.Application

.....

xl.Selection.Sort xl.Range("D2"), xlAscending, xl.Range("F2"), xlAscending,
xl.Range("A2"), xlAscending, xlYes, 1, False, xlTopToBottom

but this doesn't work (get Sort Method of Range class failed)

Anyone got any ideas why not.

It's the only line of Excel code within the program that does not work.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default Problem with VBA macro running inside VB

Range is not a property of the Excel application, but of a worksheet. You
will need to step all the way down the object model

xl.workbook_object.worksheet_object.Range("D2")

for example, or better setup object variables for each part and build an
xlRange1 object that you can use, etc.

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"David Travers" wrote in
message ...
I have created a VB6 program which uses some Excel automation to generate

an
Excel formatted document from a CSV file.

Inside Excel VBA running in Excel 2003, I have the following

Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Key2:=Range("F2") _
, Order2:=xlAscending, Key3:=Range("A2"), Order3:=xlAscending,
Header:=xlYes, OrderCustom:=1, MatchCase:=False _
, Orientation:=xlTopToBottom

however in the VB applciation i have

Dim xl as Excel.Application
Set xl = New Excel.Application

....

xl.Selection.Sort xl.Range("D2"), xlAscending, xl.Range("F2"),

xlAscending,
xl.Range("A2"), xlAscending, xlYes, 1, False, xlTopToBottom

but this doesn't work (get Sort Method of Range class failed)

Anyone got any ideas why not.

It's the only line of Excel code within the program that does not work.





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event Macro running another macro inside K1KKKA Excel Discussion (Misc queries) 1 December 20th 06 08:21 PM
Problem in running a macro from VB6 Naga Excel Discussion (Misc queries) 1 August 30th 06 12:10 AM
macro running problem hiwan99 Excel Programming 0 July 11th 05 11:04 PM
Problem with running macro on Mac computer Linking to specific cells in pivot table Excel Programming 1 June 24th 05 08:08 PM
Macro running problem Pat Excel Discussion (Misc queries) 2 May 20th 05 10:45 PM


All times are GMT +1. The time now is 06:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"