Results 1 to 6 of 6

Thread: Setting library references

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    3

    Setting library references

    Is there a way to set the library references with VBA code? That is I do not want the user to get an error message just because he/she has not checked the appropriate library in the reference list.

    ??

    Erlend

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Setting library references

    Welcome to the Forums.

    Nope, not that I know as the VBA Editor will disable the References menu when accessed by code.
    You could use late binding instead.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    3

    Re: Setting library references

    Could you please elaborate how you could use late binding to avoid a missing reference error ? ---

    Thanks

    Erlend

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Setting library references

    You dont use any reference and declare all your variables as Object.
    VB Code:
    1. Private Sub command1_click()
    2.     'Early binding... Reference required.
    3.     Dim  oAppEarly as Excel.Application
    4.     'Late binding... No reference
    5.     Dim oAppLate as object
    6.  
    7.     set oAppEarly = New Excel.Application
    8.     set oAppLate = CreateObject("Excel.Application")
    9.  
    10.     '...
    11.     '...
    12.  
    13. End Sub
    With late binding you loose the intellisense because vb doesnt know the object type.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    3

    Re: Setting library references

    Okey I think I understand this in theory but can you explain how I can use this approach with the solver library?

    That is I want the following code to work without setting a reference...


    Sub Makro1()
    ' Works fine when I have a reference to the SOLVER library
    SolverOk SetCell:="$B$16", MaxMinVal:=1, ValueOf:="0", ByChange:="$B$16"
    SolverSolve
    End Sub



    I can't seem to create a solver object where these methods are found???


    Thanks in advance....

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Setting library references

    Thats a tough one. Try looking in the registry under the HKEY_CLASSES hive for the entry of Solver.????
    You can usually find info on a references objects/props/methods by using the Object Browser in the VBA IDE. Press F2 while viewing the IDE.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width