Text in layout with vba

Text in layout with vba

Anonymous
Not applicable
1,204 Views
4 Replies
Message 1 of 5

Text in layout with vba

Anonymous
Not applicable

Hello,

 

How can i put text in a layout with a vba-code?

I want to put my name in the layout but i don't know how to get started.

 

Hope somebody can help me 

Thanks

0 Likes
1,205 Views
4 Replies
Replies (4)
Message 2 of 5

Patchy
Mentor
Mentor
0 Likes
Message 3 of 5

buianhtuan.cdt
Enthusiast
Enthusiast
'Tim kiem va nhap vao list For KIX
    Public Kix_Name As String
    Public Kix_NameEng As String
    Public Kix_No As String
    Public Kix_MU As String
    Public Kix_Qty As Integer
    Public Kix_M1UVar As Variant
    Public Kix_Cancel As Boolean
Private Sub UserForm_Initialize()
Dim TmpArr() As Variant
'Reset gia tri tim kiem
Sheets("10.LISTDATA").Range("N1").Value = ""
'Tim dong cuoi trong bang du lieu
Dim dongcuoi As Integer
dongcuoi = Sheets("10.LISTDATA").Cells(Rows.Count, 4).End(xlUp).Row

'Khai bao mang du lieu va gan vao listbox
ReDim Preserve PartListArr(1 To dongcuoi, 1 To 7)
For i = 1 To dongcuoi
    PartListArr(i, 1) = ThisWorkbook.Sheets("10.LISTDATA").Cells(i, 1).Value
    PartListArr(i, 2) = ThisWorkbook.Sheets("10.LISTDATA").Cells(i, 4).Value
    PartListArr(i, 3) = ThisWorkbook.Sheets("10.LISTDATA").Cells(i, 5).Value
    PartListArr(i, 4) = ThisWorkbook.Sheets("10.LISTDATA").Cells(i, 8).Value
    PartListArr(i, 5) = ThisWorkbook.Sheets("10.LISTDATA").Cells(i, 10).Value
    PartListArr(i, 6) = ThisWorkbook.Sheets("10.LISTDATA").Cells(i, 12).Value
    PartListArr(i, 7) = ThisWorkbook.Sheets("10.LISTDATA").Cells(i, 13).Value
Next
PartListData.ColumnCount = 7
PartListData.ColumnWidths = "100,100,100,100,100,100,100"
PartListData.List() = PartListArr()

'Gan gia tri cho ComboBox Type
ComboBoxType.List = Func20110301CreatDropList("10.LISTDATA", 1)

'Gan gia tri cho ComboBox Material
ComboBoxMat.List = Func20110301CreatDropList("10.LISTDATA", 5)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''Add for KIX''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim MenuWS As Worksheet
    Dim ProjectName As String
    Dim Filter_Type As String
    Set MenuWS = ThisWorkbook.Sheets("MENU")
    ProjectName = MenuWS.Range("K1").Value
    Select Case ProjectName
        Case "KIX"
            Filter_Type = "KIX"
    End Select
    ComboBoxType.Value = Filter_Type

End Sub
Private Sub PartListData_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

    DescriptionValue = PartListData.List(PartListData.ListIndex, 1)
    MaterialValue = PartListData.List(PartListData.ListIndex, 2)
    RemarksValue = PartListData.List(PartListData.ListIndex, 3)
    MUValue = PartListData.List(PartListData.ListIndex, 4)
   
'Add for KIX
'Define ProjectName
    Dim MenuWS As Worksheet
    Dim ProjectName As String
    Dim Filter_Type As String
    Set MenuWS = ThisWorkbook.Sheets("MENU")
    ProjectName = MenuWS.Range("K1").Value
    Select Case ProjectName
        Case "KIX"
        Case Else
            Unload Me
            Exit Sub
    End Select

'Nhap so luong
'Tao Prompt cho InputBox
    Dim StrPrompt As String: StrPrompt = "Nhap so luong:"
    Dim StrTitle As String: StrTitle = "Nhap so luong"
    Dim InputBoxType As Integer: InputBoxType = 1   'Chi nhap gia tri so
    Dim StrDefautValue As Integer: StrDefautValue = 1
    Dim StrResult As Integer
    Dim ResultArr As Variant
    StrResult = Application.InputBox(StrPrompt, StrTitle, StrDefautValue, , , , , InputBoxType)
'when cancel
    If VarType(StrResult) = vbBoolean Or StrResult = 0 Then
        Kix_Cancel = True
        Unload Me
        Exit Sub
    Else
        Kix_Qty = StrResult
    End If
    
'Tinh khoi luong cua Unit
    Kix_M1UVar = PartListData.List(PartListData.ListIndex, 4)
    Select Case VarType(Kix_M1UVar)
        Case vbEmpty
            Kix_MU = ""
        Case Else
            Kix_M1UVar = CDbl(Kix_M1UVar)
            Kix_M1UVar = Kix_M1UVar * Kix_Qty
            If Kix_M1UVar = CInt(Kix_M1UVar) Then
                Kix_MU = Kix_M1UVar & ".0"
            Else
                Kix_MU = Kix_M1UVar
            End If
    End Select
    
    Kix_Name = PartListData.List(PartListData.ListIndex, 1)
    Kix_NameEng = PartListData.List(PartListData.ListIndex, 2)
    Kix_No = PartListData.List(PartListData.ListIndex, 3)
    Unload Me
End Sub

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Application.EnableEvents = False
    Dim a As Integer
    If Not Intersect(Range("A2:A50"), Target) Is Nothing And Target.Count = 1 Then
        a = Target.Row
        Kix_Cancel = False
        PartListSearch.Show
    End If
    If Kix_Cancel = True Then
        Application.EnableEvents = True
        Exit Sub
    End If
'Xoa du lieu cu
    Range("D" & a & ":" & "N" & a).Value = ""
    Range("D" & a & ":" & "N" & a).Interior.ColorIndex = 6
    Range("A" & a).Interior.ColorIndex = 6
    
'Nhap cac gia tri
    Range("D" & a).Value = Kix_Name
    Range("E" & a).Value = Kix_NameEng
    Range("F" & a).Value = Kix_No
    Range("L" & a).Value = Kix_MU
    Range("M" & a).Value = Kix_Qty


Application.EnableEvents = True
End Sub



0 Likes
Message 4 of 5

norman.yuan
Mentor
Mentor

It is quite mystical to see @buianhtuan.cdt keeps posting replies with lengthy code, which is very hard to read, and often out-of-topic, to some very old discussion threads :-). Hope it would be beneficial to someone.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 5

MakCADD
Advocate
Advocate

If you need only to insert your name, 

Easiest way is to use insert field with the system user name or you can create custom property in your drawing property and insert it as a field in the text.   

 If you are looking to learn VBA objects then look for ActiveX developers guide in autocad help.

 

And look for object model ,. You will find the heirarchy of objects on autocad vba

 

 

 

 

 

0 Likes