Você está na página 1de 7
rier207 How to add and remove references using CATVBA - VB Scripting for CATIA VS CATIA MACRO TO OPENINN... | BEST CATIAVS MEMES R... | HOWTO ADD AND REMOVE RE... | EMMETT’S HOLIDAY G... VB SCRIPTING FOR CATIA V5 HOME ¥ TUTORIALS ¥ BLOG LINKS HOW TO ADD AND REMOVE REFERENCES USING CATVBA Emmett Ross | March 2,2017 | CATVBA | 2 Comments Let's say you are exporting data from CATIA to Excel or CATIA to Word, but different coworkers have different versions of Excel (Excel 2010, Excel 2003, Excel, 2013, etc.). If your users have an earlier version of MS Excel than the person that last saved the application, then the MS Excel reference will become broken, If this is the scenario then you should develop your application using early binding, but then convert it to late binding and remove the MS Excel reference entirely before it is deployed. That way the reference will not be an issue. You must, of course, ensure that the code which automates MS Excel is compatible for all versions in use by the end users. Iwill get into early versus late binding more later but for now let's pretend you already have an existing code using late binding, Iitpsiww sriptingsv5,comhow-to-ade-and:-remove-references-using-calvbal DOWNLOADS v SUCCESS STORIES Search the site Q MY TOP TEN MACROS Get Ten Useful CATIA Macro Example Codes Now RECENT ARTICLES = CATIA Macro to Open in New Window = Best CATIA V5 Memes - Prepare to Laugh! + How to add and remove references using CATVBA + Emmett's Holiday Gift Guide 2016 = Trick to Make a One Surface Join Using CATIA Macro MY BEST RESOURCES VB Scripting for CATIA VS Book Macro Pack CATIA Tips and Tricks Book How to Model Gears Tutorial PAGES + About + Blog wr ei20%7 References - ComparisonProjectV2 |) avatabie references: “AccessibittyCpAdmn 1.0 Type Library (acrobat Access 3.0 Type Library (Ci acrobrokerib (iAcretsHelper 1.0 Type Library (Ci acroleHelpershim 1.0 Type Library (Ciacuve 0 Type Library (Fl ActiveMovie control type library (Cl AdHoeReportingExcelClentL.b ade aebat 2.0 Rrses nal we tert. 4 i , location: C:\Program Files Mic osoft Offce\ Office 15EXCEL EXE Standard ! Microsoft Excel 15.0 Object Library a ‘AReference in a VBA Project is a “pointer” to a type library or DLL file that defines various objects and entities and the properties and methods of those entities. You may need to check the reference libraries in CATIA programmatically to prevent any errors from happening and so your users don't ever have to go into the VB editor. Or if there is a problem the user at least knows what to do to fix ‘The codes below show you how to: = Check what version of Excel the user has = Check what references are selected = Remove a reference + Add a reference from a file location = Use a For Each Next loop Visual Basic z 3 Dim ofxcel As Object ‘Late binding | 4 5 Set oFxcel = CreateObject ("Excel .Application") | 6 7 * retrieve VBE object, the root object that contains all d 8 9 Dim oVBE ' As VBE | 10 11 Set oVBE = CreateObject ("MSAPC. Apc"). VBE | 2 13 "Use the VBProjects collection to access the collection off 15 Din project * As VBProject 17 set project = oVBE.ActivevBProject 19 ‘count the number of references selected (to see them go t{ 21 WsgBox “The total nunber of references selected is: * & pr htpsiwwuscriptingtv8,comvhow-to-ade-and-remove-eferences-using-calvbal How to ad and remove references using CATVBA - VB Scripting for CATIA VS (ESB) « CATIA Automation Success Stories = CATIA Macro Email Course = CATIA Macro Programming Guide = CATIA Macro Syntax = CATIAV6 Macro Programming Change Units in CATIA Creating your first custom CATIA macro How to calculate the center of gravity position with Catia Macro How to measure distance between two points CATIA macro = Make money with VB Scripting for CATIA V5 = Reorder Spec Tree Macro = Screen Shot Macro = The Product Object Model = The Selection Object and Search Function = Troubleshooting CATIA macros = CATIA VS Macro Programming Review = Contact Us = Downloads = Jobs = CAD Designer = CATIA Careers + Material Yield Optimization Tutorial = Student Feedback = Tools and Resources = Ultimate Guide to CATIA Macros = CATIA Macro Pack Download = CATIAVS Tips and Tricks = VB Scripting for CATIA VS. SOCIAL an ei2017 How to ad and remove references using CATVBA - VB Scripting for CATIA VS 23. "if you want to loop through all the references to see whi 25 Dim x As Integer | 27 For x = 1 To project.References. Count | 29. Msgox project References .Tten(x).Description | 31 Next I 33. Dim Reference As Object | 35. '----IF EXCEL VERSION IS 15.0. checH 37 If oFxcel.Application.Version = "15.0" Then | 39 MsgBox "Excel is version: " & o€xcel.Application.Version | 41. ‘since Excel should be version 15 we need to remove any rq 43. For Each Reference In project References I 45 If Reference.Description = "Microsoft Excel 14.0 OH, 47 | 3 project.References.Renove Reference | 51 | 53 MsgBox "Reference for Excel 14.0 found and 55 | 37 Else \ 6 End If | 63 Next | 65 Dim i As Integer I 67 i-0 | 69 "Check to see if Excel 15.0 object Library is already seld 71 For Each Reference In project.References | B If Reference.Description = ficrosoft Excel 15.0 Oe 83. Next | 85 If i> @ Then | 87 ‘Excel 15 reference already added | 89. MsgBox “Excel 15 already added. I htpsiwwuscriptingtv5,comvhow-to-ade-and-remove-references-using-calvbal & v¥ 8 ese FORUMS = CATIA Macro Programming FORUM LOGIN Log in - or - Register RECENT COMMENTS = T)on CATIA Macro for captures and annotations = Tibidoul on The Product Object Model = Shad on CATIA Macro for captures and annotations = sandeep on CATIA Macro Pack Download = abdelhamid mili on Ultimate Guide to CATIA Macros Seleccionar idioma | ¥ ar ei2017 How to add and remove references using CATVBA - VB Scripting for CATIA VS 91 Else | 92 93 "need to add excel 15 | 94 95 _project.References.AddFromFile "C:\Program Files\Micrd 96 97 ‘conversely, if you want to add 14 it might look Like thiq 98 99. * project.References.AddFromFile "C:\Program Files (x86)\4 100 101 MsgBox "reference to 15 added” | 302 103 End IF | 104 405 End IF | 106 107 End Sub If there is a reference in the VB Project that refers to a library that VBA cannot find on the local machine, VBA marks that reference as MISSING in the References dialog box. Available References M Microsoft VeScrnt Regular Expressions 1.0 - ations Extensa 5. ee SpartercMenager 0" ypeUbery IE] (CAcressinitycrimn 1.0 Type Library ED Dacp 1.0 Type Library + acrobat ao (DlAcrobat Access 3.0 Type Library Priority Acrobat oistiler acrobat Scan 1.0 Type Library + Ci acrobat WebCapture 1,0 Type Library (D Acrobat WebCapture IE Toolbar Favorites 1.0 Type Di acroBrokertib [) acniesner1.0-Tune rary i , MISSING: Microsoft Excel 15.0 Osject brary Location: C:\Program Fles\Mcroscft Offce|OFice15\EXCEL.OE Language: Standard If the reference is already missing, you will probably not be able to remove it via VBA, but you can trigger a message box warning the user that he needs to manually remove the missing reference before the program can be run successfully. Option Explicit 2 3. Sub RemoverefO) 4 5. Dim theRef As Variant, i As Long 6 7 Dim oVBE ' As VBE 8 9. Set oVBE = CreateObject ("MSAPC. Apc”). VBE 0 11 ‘Use the VBProjects collection to access the collection of @ 13 Dim project * As VBProject 4 15 Set project = oVBE.ActiveVBProject htpsiwwuscriptingtv5,comvhow-to-ade-and-remove-references-using-calvbal an ei2017 How to ad and remove references using CATVBA - VB Scripting for CATIA VS 16 17 On Error Resume Next I 19 For i = project.References.Count To 1 Step -1 | 21 Set theRef = project.References.ItemCi) | 23 If theRef.IsBroken = True Then | 25 project References. Renove theRef | 27 End If | 29 Next 1 Tf Err = @ Then 2 3 MsgBox "Missing ref encountered!" & "You will need to removd 4 5 End If | 6 7 On Error GoTo @ | 8 9 End Sub Overall, the code could probably be better but I wanted to give a few examples on a couple of different things all at once and try to get you thinking. Have you ever had to do anything like this or had any trouble with references? Please let me know! RELATED POSTS HOW To MODEL WHEN TO USE GEARS USING VBA CREATEREFERENCE No Comments | No Comments | Sep 11, 2015 ‘Aug 5, 2015 | QAND A ABOUT = UPDATED | ALIREZA REIHANI'S. SPECIFICATION TREE |g CATVBA PROJECT __ REORDER MACRO 2.Comments | Jul 16, 2015, 1. Comment | Apr 18, 2016 ABOUT THE AUTHOR Emmett Hey! I'm Emmett, and I've been called a CATIA V5 "guru". How can T help you? Download my Ten Best Macros here. htpsiwwuscriptingtv8,comvhow-to-ade-and-remove-references-using-calvbal rei20%7 How to add and remove references using CATVBA - VB Scripting for CATIA VS 2 COMMENTS Stefan | .farch 3, 2017 Reply Thanks Emmett, yesterday I talked to a colleague and tried to explain Late Binding, now I have a good example for him. Best Regards Stefan ADD A COMMENT Your email address will not be published. Required fields are marked * Comment:* Name: Email Address: * Website: ADD COMMENT Notify me of follow-up comments by email. hitpsiwwuscriptingtv8,comvhow-to-ade-and-remove-references-using-calvbal er rei2017 How to ad and remove references using CATVBA - VB Scripting for CATIA VS Notify me of new posts by email (2) & COPYRIGHT © 2017 VB SCRIPTING FOR CATIA VS, THEME BY MYTHEMESHOP, ABOUT CONTACTUS PRIVACY POLICY htpsiwwuscriptingtv8,comvhow-to-ade-and-remove-references-using-calvbal DISCLAIMER a"