+ Reply to Thread
Results 1 to 8 of 8

Import a folder into VBA Project

  1. #1
    Registered User
    Join Date
    04-21-2017
    Location
    San Francisco, USA
    MS-Off Ver
    Excel for Mac 2011
    Posts
    11

    Import a folder into VBA Project

    Hi,

    I'm on a Mac using 2016 Excel, but it fails to run a macro built (VBA project) for me that works perfectly on the Excel PC version.

    On GitHub I found 'VBA-Dictionary-1.4.1' file which when imported, apparently works around the differences between the two platforms. It all sounds good. But I have never even opened the Developer tab and VBA stuff, so I am a bit daunted.


    So how do I import this file? Dictionary.cls

    I have got the VBA project open, and I can see how to create modules, but I am just not clear on how to import such a file. Would appreciate a step-by-step approach if someone knows how to make this easy.

    Many thanks.

    (this question is cross-posted on MrExcel.com - but no complete solution found yet)
    Last edited by megaphone; 05-01-2017 at 11:43 AM.

  2. #2
    Registered User
    Join Date
    04-21-2017
    Location
    San Francisco, USA
    MS-Off Ver
    Excel for Mac 2011
    Posts
    11

    Re: Import a folder into VBA Project

    Although the topic is "Import a folder", the requirement is to just import a file.

  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Import a folder into VBA Project

    So you just want to import the Dictionary.cls?

    Unzip the zip file to location of your choice. Open Excel file, and go to VB Editor (VBE).
    Once inside VBE click in VBAProject pane and select "Import file...". Then find the .cls file you want to import and hit open.

    Follow instruction in GitHub for usage.

  4. #4
    Registered User
    Join Date
    04-21-2017
    Location
    San Francisco, USA
    MS-Off Ver
    Excel for Mac 2011
    Posts
    11

    Re: Import a folder into VBA Project

    Thanks for that advice. Some progress...

    I have imported the dictionary.cls file which now sits in a folder called Class Modules. That seems fine.

    But when I try to RUN it I get this error:
    Runtime error '429'
    ActiveX component can't create object.

    Upon debug I get this highlight:
    Set dAttributes = CreateObject("Scripting.Dictionary")
    Active X component can't create object.

    Is there anything I can do about this?

    Thanks

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Import a folder into VBA Project

    "Scripting.Dictionary" is Windows based machine specific. That is why you needed to import Dictionary.cls.

    Replace all reference to "Scripting.Dictionary" with something like below.
    Please Login or Register  to view this content.
    Read through the README file located in GitHub.
    https://github.com/VBA-tools/VBA-Dic...ster/README.md

  6. #6
    Registered User
    Join Date
    04-21-2017
    Location
    San Francisco, USA
    MS-Off Ver
    Excel for Mac 2011
    Posts
    11

    Re: Import a folder into VBA Project

    Thank you. I will try that.

  7. #7
    Registered User
    Join Date
    04-21-2017
    Location
    San Francisco, USA
    MS-Off Ver
    Excel for Mac 2011
    Posts
    11

    Re: Import a folder into VBA Project

    I did replace all the references (see below), but it still came up with the same error. I am using the 32-but version of Excel on the Mac, so in theory it should run --- but it doesn't.

    Any further suggestions?
    Thanks

    Option Explicit
    Sub GenerateResults()

    Dim LO As ListObject
    Dim LO2 As ListObject
    Dim LR As ListRow
    Dim ws As Worksheet
    Dim cCount As Integer
    Dim gCount As Integer
    Dim dAttributes As Object
    Dim dValues As Object
    Dim dKey As Variant
    Dim c As Range
    Dim v As Variant
    Dim i As Integer
    Dim InsertCount As Integer

    Set LO = ActiveSheet.ListObjects("Data")
    If LO Is Nothing Then MsgBox "Please select the table and re-run": Exit Sub
    With Application
    .EnableEvents = False
    .DisplayAlerts = False
    .ScreenUpdating = False
    End With
    LO.AutoFilter.ShowAllData

    Set ws = ActiveWorkbook.Sheets.Add
    ws.Range("A1:C1").Value = Array("Candidate", "Attribute", "Value")
    ws.ListObjects.Add xlSrcRange, Range("A1:C1"), , xlYes
    Set LO2 = ws.Range("A1").ListObject

    Set dAttributes = CreateObject(“New.Dictionary")
    For Each c In LO.ListColumns("Attribute").DataBodyRange.Cells
    If Not dAttributes.Exists(c.Value) Then dAttributes(c.Value) = c.Value
    Next c

    For Each dKey In dAttributes.Keys
    LO.Range.AutoFilter Field:=LO.ListColumns("Attribute").Index, Criteria1:=dKey
    gCount = Evaluate("SUM(--(FREQUENCY(IF(" & LO.Name & "[Attribute]=""" & dKey & """,MATCH(" & LO.Name & "[Value]," & LO.Name & "[Value],0)),ROW(" & LO.Name & "[Value])-ROW(" & LO.Name & "[[#Headers],[Value]]))>0))")
    cCount = Evaluate("SUM(--(FREQUENCY(IF(" & LO.Name & "[Attribute]=""" & dKey & """,MATCH(" & LO.Name & "[Candidate]," & LO.Name & "[Candidate],0)),ROW(" & LO.Name & "[Candidate])-ROW(" & LO.Name & "[[#Headers],[Candidate]]))>0))")
    v = GenerateSplit(cCount, gCount)
    Set dValues = CreateObject(“New.Dictionary")

    For Each c In LO.ListColumns("Value").DataBodyRange.SpecialCells(xlCellTypeVisible)
    If Not dValues.Exists(c.Value) Then dValues(c.Value) = c.Value
    Next c

    InsertCount = 0
    i = 1
    For Each c In LO.ListColumns("Candidate").DataBodyRange.SpecialCells(xlCellTypeVisible)
    TryAgain:
    If i <= v(InsertCount, 2) Then
    Set LR = LO2.ListRows.Add
    LR.Range.Value = Array(c.Value, dKey, dValues.Items()(InsertCount))
    i = i + 1
    Else
    i = 1
    InsertCount = InsertCount + 1
    GoTo TryAgain
    End If
    Next c

    Next dKey
    LO.AutoFilter.ShowAllData
    LO.Range.Worksheet.Select

    With Application
    .EnableEvents = True
    .DisplayAlerts = True
    .ScreenUpdating = True
    End With

    End Sub

  8. #8
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Import a folder into VBA Project

    Don't use "CreateObject()". Dictionary.cls is class module and treated as such (see how I set dAttributes in post #5). Also dAttributes should be dimmed as Dictionary not object.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Import VBA code to SPECIFIED project
    By VitoBdG in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-17-2015, 11:08 AM
  2. Import data into excel from MS Project
    By egavasrg in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-28-2011, 05:10 PM
  3. Replies: 1
    Last Post: 01-24-2006, 11:35 AM
  4. Replies: 1
    Last Post: 01-24-2006, 11:00 AM
  5. Replies: 1
    Last Post: 01-24-2006, 12:25 AM
  6. Microsoft project import export template
    By Hamendra Arora in forum Excel General
    Replies: 1
    Last Post: 05-18-2005, 06:06 PM
  7. How do I import MS Project data into Excel?
    By mk in forum Excel General
    Replies: 0
    Last Post: 03-16-2005, 01:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1