Results 1 to 10 of 10
  1. #1
    Lounger
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to find GUID? (excel and autocad)

    Hi guys,
    Got a bunch of codes here that can help me check the refference library and the add them if i do not have them checked.

    Sub AddReference()

    Dim strGUID As String, theRef As Variant, i As Long

    strGUID = "{00020905-0000-0000-C000-000000000046}"
    On Error Resume Next

    For i = ThisWorkbook.VBProject.References.Count To 1 Step -1
    Set theRef = ThisWorkbook.VBProject.References.Item(i)
    If theRef.isbroken = True Then
    ThisWorkbook.VBProject.References.Remove theRef
    End If
    Next i

    Err.Clear

    ThisWorkbook.VBProject.References.AddFromGuid _
    GUID:=strGUID, Major:=1, Minor:=0

    Select Case Err.Number
    Case Is = 32813

    Case Is = vbNullString

    Case Else

    MsgBox "A problem was encountered trying to" & vbNewLine _
    & "add or remove a reference in this file" & vbNewLine & "Please check the " _
    & "references in your VBA project!", vbCritical + vbOKOnly, "Error!"
    End Select
    On Error Goto 0
    End Sub

    Questions;
    What should i add in the codes if there is more than 1 refference that i want to add?
    &
    Where can i find the GUID list for these library that i wanna add?
    (wanted to add autocad library )

    Thank you

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to find GUID? (excel and autocad)

    I usually circumvent the problem by using late binding:

    Dim oAC as Object
    Set oAC=CreateObject("Whatever Autocad Is Called")
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How to find GUID? (excel and autocad)

    You can find the class ID (GUID) for a library by looking for it in the HKEY_CLASSES_ROOTTypeLib part of the Windows registry, or by creating a list of all references in a workbook that has the required reference:

    Sub ListRefs()
    Dim ref
    For Each ref In ActiveWorkbook.VBProject.References
    Debug.Print ref.Name, ref.GUID
    Next ref
    End Sub

    If you want to add more than one reference, just add more lines with AddFromGUID.

  4. #4
    Lounger
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to find GUID? (excel and autocad)

    thanks,
    Found the GUID just fine.
    my comp hang a few times because i forgot to turn of the security.
    Will my comp be vulnerable if i turn the marco security off?

    thanks again

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How to find GUID? (excel and autocad)

    In theory, you become vulnerable to macro virus attacks if you lower macro security and/or allow access to the Visual Basic Project. But if you have an up-to-date antivirus program, that should catch infected documents; moreover, I haven't heard much about VBA macro viruses for a while now.

  6. #6
    Lounger
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to find GUID? (excel and autocad)

    Thanks for the info Hans,
    One more question, I am going to share the worksheet to other people and i have updated the toolbar that we have,
    when i open the new worksheet(that have new toolbar) the old one is still there, unchange.
    How can i do this changes??

    Please advise

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How to find GUID? (excel and autocad)

    You need to do two things:

    1) Attach your custom toolbar to the workbook:
    - Open your workbook.
    - Select Tools | Customize...
    - Activate the Toolbars tab.
    - Click Toolbars...
    - Select your custom toolbar in the list on the left.
    - Click Copy >> to copy the toolbar into your workbook.
    - Click OK, then close the Customize dialog.
    - Save your workbook now!

    2) Delete the toolbar each time the workbook is closed. Put the following code in the ThisWorkbook module of your workbook:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    ' Suppress error message if toolbar has already been deleted
    On Error Resume Next
    ' Delete custom toolbar
    Application.CommandBars("MyToolbar").Delete
    End Sub

    where MyToolbar is the name of your toolbar.

  8. #8
    Lounger
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to find GUID? (excel and autocad)

    Hans,
    Thanks for the input.
    If i use visible instead of delete, will there be any problem?

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How to find GUID? (excel and autocad)

    Hiding the toolbar is not sufficient. You *must* delete it when the workbook is closed, so that you'll use an up-to-date version of the toolbar next time you open the workbook.

  10. #10
    Lounger
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to find GUID? (excel and autocad)

    Hans,
    I get it now.
    thanks.

Posting Permissions

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