Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
123 views

Vba Entre Autocad Et Excel: Comptage Des Blocks

This document describes a VBA script that counts blocks in an AutoCAD drawing and exports the results to an Excel spreadsheet. The script declares variables, launches Excel and formats a table, then loops through each entity in the drawing to count block references. It formats the spreadsheet with colors and borders. Finally, it saves the Excel file.

Uploaded by

Hadi Othmane
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
123 views

Vba Entre Autocad Et Excel: Comptage Des Blocks

This document describes a VBA script that counts blocks in an AutoCAD drawing and exports the results to an Excel spreadsheet. The script declares variables, launches Excel and formats a table, then loops through each entity in the drawing to count block references. It formats the spreadsheet with colors and borders. Finally, it saves the Excel file.

Uploaded by

Hadi Othmane
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

VBA entre AutoCAD et EXCEL :

Comptage des Blocks

1
Plan :

Introduction :

Projet VBA :

Application :

Conclusion :
2
Introduction :

AutoCAD
VBA

Blocks
Excel

3
Projet VBA :
Déclaration des variables :

Dim Excel As Object


Dim ExcelSheet As Object
Dim ExcelWorkbook As Object
Dim Chemin As String
Dim NomFichier As String
Chemin = "C:\Users\othma\Desktop\"
NomFichier = "Test.xlsx"
Dim RowNum As Integer
Dim elem As AcadEntity
Dim x As Integer
Dim y As Integer

4
Projet VBA :
Lancer Excel et dessin du Tableau :
Set Excel = CreateObject("Excel.Application")
Set ExcelWorkbook = Excel.Workbooks.Add
Set ExcelSheet = Excel.ActiveSheet

ExcelSheet.Cells(1, 4) = "N°"
ExcelSheet.Cells(1, 5) = "Désignation"
ExcelSheet.Cells(1, 6) = "Unité"
ExcelSheet.Cells(1, 7) = "Qté"

For x = 4 To 7
ExcelSheet.Cells(1, x).Borders.Value = 1
ExcelSheet.Cells(1, x).Interior.color = RGB(255, 102, 0)
Next x

y=2
ExcelSheet.Cells(2, 5).ColumnWidth = 28
5
Projet VBA :
Comptage des blocks :

For Each elem In ThisDrawing.ModelSpace

With elem
ElseIf ExcelSheet.Cells(RowNum, 5) = elem.Name Then
If TypeOf elem Is AcadBlockReference Then
ExcelSheet.Cells(RowNum, 7).Value = ExcelSheet.Cells(RowNum, 7).Value + 1
Exit For
For RowNum = 2 To y
End If
If ExcelSheet.Cells(RowNum, 5) = "" Then
Next RowNum
ExcelSheet.Cells(RowNum, 5) = elem.Name
End If
ExcelSheet.Cells(RowNum, 6) = "U"
End With
ExcelSheet.Cells(RowNum, 7).Value = 1
Next elem
y=y+1

6
Projet VBA :
Côté esthétique :

For RowNum = 2 To y – 1

ExcelSheet.Cells(RowNum, 5).Interior.color = RGB(218, 238, 243)


ExcelSheet.Cells(RowNum, 4).Interior.color = RGB(251, 168, 106)
ExcelSheet.Cells(RowNum, 4).ColumnWidth = 4
ExcelSheet.Cells(RowNum, 4) = RowNum - 1
ExcelSheet.Cells(RowNum, 4).Borders.Value = 1
ExcelSheet.Cells(RowNum, 5).Borders.Value = 1
ExcelSheet.Cells(RowNum, 6).Borders.Value = 1
ExcelSheet.Cells(RowNum, 7).Borders.Value = 1

Next RowNum

7
Projet VBA :
Enregistrer le travail :

ExcelWorkbook.SaveAs Chemin & NomFichier


Excel.Application.Quit

8
Application :

9
Conclusion

You might also like