Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Scripting Dictionary to hold User Defined Type

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
billbell52 - 18 Sep 2007 15:18 GMT
I have an array of user defined types that hold info about some
columns in the spreadsheet.  I currently loop through to find the
column name I am interested in.  I would like to use the scripting
dictionary to do this since I think it would be a little faster.  I do
this a lot in my addin.  I have tried numerous things and it does not
appear to allow this.  I thought someone may know of a way to do it.
Here is a simplified test case.

I thought of having the dictionary hold the index to the array of user
defined types.  This would work but it would be cumbersome to manage.
Perl and Ruby do this with ease.

Option Explicit

 Public Type headUT
 colName As String
 colWidth As Integer
 End Type

Sub testdic()

 ' Add reference to Microsoft Scripting Dictionary.

 Dim xDic As New Scripting.Dictionary
 Dim x() As Variant
 Dim z() As headUT

 ReDim x(0)
 ReDim z(0)
' Assign values to user defined type
 z(0).colName = "This column"
 z(0).colWidth = 12
' Cannot assign User type directly to Dictionary .
 xDic("COL_INFO") = z(0)        ' Comment out to try next item
' Cannot assign User type to Variant then assign variant to
Dictionary
 x(0) = z(0)
 xDic("COL_INFO") = x(0)   'Can assign variant to dictionary
End Sub
Jim Rech - 18 Sep 2007 15:44 GMT
>> I think it would be a little faster.

I'd happily bet the other side.  Array processing is pretty quick in Excel
and the Dictionary object is pretty slow.

Frankly I think you might be going about this the hard way.  How about:

ActiveCell.EntireColumn.Name = "ThisColumn"

and later:

MsgBox Names("ThisColumn").RefersToRange.Column

Signature

Jim

|I have an array of user defined types that hold info about some
| columns in the spreadsheet.  I currently loop through to find the
[quoted text clipped - 35 lines]
|  xDic("COL_INFO") = x(0)   'Can assign variant to dictionary
| End Sub
Dana DeLouis - 18 Sep 2007 15:59 GMT
I couldn't get it to work either.
Would this be a workaround?

 z(0).colName = "This column"
 z(0).colWidth = 12
 xDic.Add "Col_Info", Array(z(0).colName, z(0).colWidth)

Signature

HTH   :>)
Dana DeLouis

>I have an array of user defined types that hold info about some
> columns in the spreadsheet.  I currently loop through to find the
[quoted text clipped - 35 lines]
>  xDic("COL_INFO") = x(0)   'Can assign variant to dictionary
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.