Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Reading a Range from a VB6 DLL

Hi,

I have a visual basic 6 DLL sub that is called from a vba sub in
Excel. I can't get the DLL to find the used range in the activesheet
and loop through each cell, categorize it and put it into an array.

Any suggestions much appreciated.

Thank you in advance.

Meldrum
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Reading a Range from a VB6 DLL

Simplest might be to assign the range to a variant array, pass the array to
the dll
as an argument and return the new array.
Another option is to pass the Excel application as an object to the dll and
in the
dll drill down to the used range etc.
What code have you got now?

RBS


wrote in message
...
Hi,

I have a visual basic 6 DLL sub that is called from a vba sub in
Excel. I can't get the DLL to find the used range in the activesheet
and loop through each cell, categorize it and put it into an array.

Any suggestions much appreciated.

Thank you in advance.

Meldrum


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Reading a Range from a VB6 DLL

Presumably, your DLL has some reference to the Excel application. If the DLL
is a COM Add-In, the Application parameter of the OnConnection event is a
reference to the host application, in this case, Excel.Application. If it
is just an Automation Add-In, with no intrinsic reference to the
Excel.Application (but was compiled with the Excel typelib), you can get a
reference to the Excel.Application and therefore anything else in Excel,
with code such as

Function Test(RR As Excel.Range) As String
Dim XLApp As Excel.Application
Dim ActWB As Excel.Workbook
Dim ActWS As Excel.Worksheet ' ignoring other Sheet types
Dim URng As Excel.Range

Set XLApp = RR.Application
Set ActWB = XLApp.ActiveWorkbook
Set ActWS = XLApp.ActiveSheet
Set URng = ActWS.UsedRange
Test = "WB: " & ActWB.Name & " WS: " & ActWS.Name & " URng: " &
URng.Address
End Function

This will return a string like

WB: Book2.xlsm WS: Sheet1 URng: $A$1:$D$3

indicating the ActiveWorkbook, ActiveSheet, and UsedRange.

If you need to move the used range values in and out of a range, try
somthing like


Function Test(RR As Excel.Range) As String
Dim XLApp As Excel.Application
Dim ActWB As Excel.Workbook
Dim ActWS As Excel.Worksheet ' ignoring other Sheet types
Dim URng As Excel.Range
Dim Arr() As Variant
Dim R As Long
Dim C As Long

Set XLApp = RR.Application
Set ActWB = XLApp.ActiveWorkbook
Set ActWS = XLApp.ActiveSheet
Set URng = ActWS.UsedRange
'Test = "WB: " & ActWB.Name & " WS: " & ActWS.Name & " URng: " &
URng.Address
ReDim Arr(1 To URng.Rows.Count, 1 To URng.Columns.Count)
For R = 1 To UBound(Arr, 1)
For C = 1 To UBound(Arr, 2)
Arr(R, C) = URng.Cells(R, C)
Next C
Next R

' DEBUG ONLY
For R = 1 To UBound(Arr, 1)
For C = 1 To UBound(Arr, 2)
Debug.Print R, C, Arr(R, C)
Next C
Next R
End Function

You might want to include some additional details about the exact nature of
the problem you are having.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)



wrote in message
...
Hi,

I have a visual basic 6 DLL sub that is called from a vba sub in
Excel. I can't get the DLL to find the used range in the activesheet
and loop through each cell, categorize it and put it into an array.

Any suggestions much appreciated.

Thank you in advance.

Meldrum


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Reading a Range from a VB6 DLL

On 17 Nov, 16:10, "RB Smissaert"
wrote:
Simplest might be to assign the range to a variant array, pass the array to
the dll
as an argument and return the new array.
Another option is to pass the Excel application as an object to the dll and
in the
dll drill down to the used range etc.
What code have you got now?

RBS

wrote in message

...



Hi,


I have a visual basic 6 DLL sub that is called from a vba sub in
Excel. I can't get the DLL to find the used range in the activesheet
and loop through each cell, categorize it and put it into an array.


Any suggestions much appreciated.


Thank you in advance.


Meldrum- Hide quoted text -


- Show quoted text -


RBS / Chip

Thank you for you quick replies. I have managed to read the range by
passing the no of rows and columns as a long/iinteger respectively.

Cheers

Meldrum
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
HELP! Reading range into array katem[_2_] Excel Programming 2 June 8th 07 06:51 AM
Reading a Range to an Array Kevin H. Stecyk[_2_] Excel Programming 6 January 26th 05 11:01 PM
Reading Entire Range Peter[_46_] Excel Programming 1 September 17th 04 04:20 PM
Reading a Range Pablo Excel Programming 2 June 4th 04 02:59 PM
Reading a named range Karl Thompson Excel Programming 1 July 10th 03 02:29 AM


All times are GMT +1. The time now is 01:10 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"