Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PM PM is offline
external usenet poster
 
Posts: 16
Default transferring code from VBA to a VB dll

Greetings and reverence to all gurus ! (with a special notice for Stephen
Bullen ;-))


Nothing more simple than copy a range ? This code works normally in VBA:

Sheets(1).Select
ActiveSheet.Range(Cells(l1, 1), Cells(l2, 2)).Select
Selection.Copy
Sheets(2).Select
Cells(2, 1).Select
Sheets(2).Paste

In fact, this code is generated by the macro recorder.

The following is the translation in my VB dll :

Set mySheet = XLS.Sheets(1) 'XLS represents my Workbook
mySheet.Activate 'this line is correctly
implemented
With mySheet
.Range(Cells(l1, 1), Cells(l2, 2)).copy

This last line fails. It is Range that fails :
set r = .Range(Cells(l1, 1), Cells(l2, 2)) also fails (method '~'
failed)

Anyone know why ? And how to get around this ?



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default transferring code from VBA to a VB dll

PM,

I expect that you need to be more specific with your cells object, since
your VBA depends on defaults. Cells defaults to the cells collection of the
activesheet, but more specific would be:
VBA:
Old: ActiveSheet.Range(Cells(l1, 1), Cells(l2, 2)).Select

New: ActiveSheet.Range(ActiveSheet.Cells(l1, 1), ActiveSheet.Cells(l2,
2)).Select

So try:

With mySheet
.Range(.Cells(l1, 1), .Cells(l2, 2)).copy

HTH,
Bernie
MS Excel MVP

"PM" wrote in message
...
Greetings and reverence to all gurus ! (with a special notice for Stephen
Bullen ;-))


Nothing more simple than copy a range ? This code works normally in VBA:

Sheets(1).Select
ActiveSheet.Range(Cells(l1, 1), Cells(l2, 2)).Select
Selection.Copy
Sheets(2).Select
Cells(2, 1).Select
Sheets(2).Paste

In fact, this code is generated by the macro recorder.

The following is the translation in my VB dll :

Set mySheet = XLS.Sheets(1) 'XLS represents my Workbook
mySheet.Activate 'this line is correctly
implemented
With mySheet
.Range(Cells(l1, 1), Cells(l2, 2)).copy

This last line fails. It is Range that fails :
set r = .Range(Cells(l1, 1), Cells(l2, 2)) also fails (method '~'
failed)

Anyone know why ? And how to get around this ?





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default transferring code from VBA to a VB dll

Try

With mySheet
.Range(.Cells(l1, 1), .Cells(l2, 2)).copy


--

HTH

RP
(remove nothere from the email address if mailing direct)


"PM" wrote in message
...
Greetings and reverence to all gurus ! (with a special notice for Stephen
Bullen ;-))


Nothing more simple than copy a range ? This code works normally in VBA:

Sheets(1).Select
ActiveSheet.Range(Cells(l1, 1), Cells(l2, 2)).Select
Selection.Copy
Sheets(2).Select
Cells(2, 1).Select
Sheets(2).Paste

In fact, this code is generated by the macro recorder.

The following is the translation in my VB dll :

Set mySheet = XLS.Sheets(1) 'XLS represents my Workbook
mySheet.Activate 'this line is correctly
implemented
With mySheet
.Range(Cells(l1, 1), Cells(l2, 2)).copy

This last line fails. It is Range that fails :
set r = .Range(Cells(l1, 1), Cells(l2, 2)) also fails (method '~'
failed)

Anyone know why ? And how to get around this ?





  #4   Report Post  
Posted to microsoft.public.excel.programming
PM PM is offline
external usenet poster
 
Posts: 16
Default transferring code from VBA to a VB dll

YES !!

Your perfectly right. I am still infused with VBA style writing.
Thanks a million ! I just couldn't see it before you said it !

Pat

"Bernie Deitrick" <deitbe @ consumer dot org a écrit dans le message de
news: ...
PM,

I expect that you need to be more specific with your cells object, since
your VBA depends on defaults. Cells defaults to the cells collection of
the
activesheet, but more specific would be:
VBA:
Old: ActiveSheet.Range(Cells(l1, 1), Cells(l2, 2)).Select

New: ActiveSheet.Range(ActiveSheet.Cells(l1, 1), ActiveSheet.Cells(l2,
2)).Select

So try:

With mySheet
.Range(.Cells(l1, 1), .Cells(l2, 2)).copy

HTH,
Bernie
MS Excel MVP

"PM" wrote in message
...
Greetings and reverence to all gurus ! (with a special notice for Stephen
Bullen ;-))


Nothing more simple than copy a range ? This code works normally in VBA:

Sheets(1).Select
ActiveSheet.Range(Cells(l1, 1), Cells(l2, 2)).Select
Selection.Copy
Sheets(2).Select
Cells(2, 1).Select
Sheets(2).Paste

In fact, this code is generated by the macro recorder.

The following is the translation in my VB dll :

Set mySheet = XLS.Sheets(1) 'XLS represents my Workbook
mySheet.Activate 'this line is correctly
implemented
With mySheet
.Range(Cells(l1, 1), Cells(l2, 2)).copy

This last line fails. It is Range that fails :
set r = .Range(Cells(l1, 1), Cells(l2, 2)) also fails (method '~'
failed)

Anyone know why ? And how to get around this ?







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default transferring code from VBA to a VB dll


.Range(Cells(l1, 1), Cells(l2, 2)).copy

note that Cells refers to the activesheet! as it is not qualified,
try like :

.Range(.Cells(l1, 1), .Cells(l2, 2)).copy


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"PM" wrote :

Greetings and reverence to all gurus ! (with a special notice for
Stephen Bullen ;-))


Nothing more simple than copy a range ? This code works normally in
VBA:

Sheets(1).Select
ActiveSheet.Range(Cells(l1, 1), Cells(l2, 2)).Select
Selection.Copy
Sheets(2).Select
Cells(2, 1).Select
Sheets(2).Paste

In fact, this code is generated by the macro recorder.

The following is the translation in my VB dll :

Set mySheet = XLS.Sheets(1) 'XLS represents my Workbook
mySheet.Activate 'this line is
correctly implemented
With mySheet
.Range(Cells(l1, 1), Cells(l2, 2)).copy

This last line fails. It is Range that fails :
set r = .Range(Cells(l1, 1), Cells(l2, 2)) also fails (method '~'
failed)

Anyone know why ? And how to get around this ?





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
Transferring files from a MAC jms2106 Excel Discussion (Misc queries) 1 April 20th 10 11:52 PM
transferring data tofimoon4[_9_] New Users to Excel 6 April 17th 09 09:00 PM
transferring data Chad[_5_] Excel Discussion (Misc queries) 5 February 25th 09 08:11 AM
Transferring data tofimoon4[_2_] Excel Discussion (Misc queries) 17 February 24th 09 07:29 PM
transferring cells.. marketing123 Excel Discussion (Misc queries) 2 August 6th 07 06:32 PM


All times are GMT +1. The time now is 01:29 AM.

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

About Us

"It's about Microsoft Excel"