When passing arguments to a procedure (sub or function) the default will be 'byRef' in Excel VBA, thus you don't have to write 'byRef' before the variable. If you want to pass ByVal you have to explicitly write 'ByVal' before the variable. When using ByVal you are only passing a copy of the argument to… Continue reading ByRef vs ByVal
Tag: excel
Check If Each Input Box is filled
Many times you don't want a user to proceed until all input boxes are filled. To solve this you can loop through each control with a For Each statement. For Each will be especially useful when you there are many controls and you don't want to reference each name individually. The examples below show how… Continue reading Check If Each Input Box is filled
Clear All Check Boxes In Excel VBA Userform
This example uses a for each loop so that each check box name does not have to be explicitly written out. This is useful when you are adding more control and limit the amount of code you are writing. Better Method Dim ctrl As Control Sub ClearAllButton_Click() For Each ctrl In exportFilesUF.Controls If TypeName(ctrl) =… Continue reading Clear All Check Boxes In Excel VBA Userform
Find Intersect Between Two Block Objects
This code will create two blocks that have a light weight polyline of a triangle and a trapezoid. We want the two object to have a specific gap between them without intersecting. WE CAN DO THIS! No Calculus required. We do this by exploding the block and then offsetting the polyline a specific distance with… Continue reading Find Intersect Between Two Block Objects
Compile Bill of Materials and Remove Duplicates
This example builds upon the methods of finding duplicate data. See https://pearlsnake.com/2019/06/20/find-and-delete-rows-with-duplicate-data/ In order for a row to be complied, Column A, E and K have to match the data in other rows. After running the example the data was been reduced from 35 rows to 30 rows. This helps purchasing departments so they don't… Continue reading Compile Bill of Materials and Remove Duplicates
Find and Delete Rows With Duplicate Data
This code will use the collection object to quickly determine if data is a duplicate. It uses the .add method and will return an error if the data is already in the collection and wont be added. We can also use .count method to see if that item was added to the collection or not.… Continue reading Find and Delete Rows With Duplicate Data
AddSpline Method
This example will grab scanned data from an excel file and create a visual representation of the scan data in AutoCAD by drawing splines. I haved uploaded the excel file for viewing reference Scan Data_to_Autocad.xlsm Results: Drawn Splines Excel Scanned Data Option Explicit Public MTextObj As AcadMText Public ACLayout As AcadLayout Public acadApp As Object… Continue reading AddSpline Method
Grab Attribute Data from Dwg Files in a Folder
This example will let user select a folder that contains dwg files. It then opens each drawing and extracts attribute data from all the blocks. The data is then put in an excel table. The table is then sorted according to the y coordinate insertion point of each block. For this example I have a… Continue reading Grab Attribute Data from Dwg Files in a Folder
Delete All Drawing Objects
This is useful when you are creating drawings from a template that has inserted blocks or pre-drawn objects. It is also helps when creating many CNC drawings. Instead of creating a new drawing each time, just create one drawing, create objects, save as, delete all, create objects, save as, and repeat until all the CNC… Continue reading Delete All Drawing Objects
Editing Dynamic Block Attributes
Paste the following code into excel VBA module. Next add a folder named 'support' and put the dwg file that has all your dynamic blocks. Keep the 'support' folder in the same folder as the excel workbook. See this post on creating dynamic blocks https://pearlsnake.com/2019/05/20/creating-dynamic-blocks-in-autocad/ . I have also uploaded a folder called 'support' on… Continue reading Editing Dynamic Block Attributes