HenlodeWaal

Create tables in ProcessBook using VBA

Discussion created by HenlodeWaal Champion on Jul 13, 2015

Just a simple VBA code that creates tables and columns, I know you can use the build-in Symbol Library "Basic Shape" grids but it does not fit my needs,....yet. Play around and post any mods that you can think of to improve its usage. Copy and paste this code in VBA and simply click on your display the top left most corner of where you want your table to start.

 

Dim Table_Width As Integer

'Dim Table_Height As Integer

Dim Column_Count As Integer

Dim Column_Width As Integer

 

 

Dim Row_Count As Integer

Dim Row_Height As Integer

 

 

Public Sub CREATE_TABLE()

 

 

Table_Width = 1700                          'Can be replaced by variable

Column_Count = 5                            'Can be replaced by variable

Column_Width = Table_Width / Column_Count   'Evenly spaced columns

Row_Count = 10                              'Can be replaced by variable

Row_Height = 53                             'Can be replaced by variable

 

 

End Sub

 

 

Private Sub Display_Click(ByVal lvarX As Long, ByVal lvarY As Long)

'not the best of actions/event to use but it works for me

 

Dim NewSymbol As Object

 

 

CREATE_TABLE

Debug.Print "LEFT:" & lvarX & vbTab & "TOP:" & lvarY

Debug.Print Column_Count & vbTab & Row_Count

   

'DRAW ROWS

Dim i As Integer

 

 

For i = 0 To Row_Count

    Set NewSymbol = ThisDisplay.Symbols.Add(pbSymbolLine)

        With NewSymbol

            .Left = lvarX

            .Top = lvarY - (i * Row_Height)

            .Width = Table_Width

            .Height = 0

        End With

Next i

 

 

'DRAW COLUMNS

Dim j As Integer

 

 

For j = 0 To Column_Count

    Set NewSymbol = ThisDisplay.Symbols.Add(pbSymbolLine)

        With NewSymbol

            .Left = lvarX + (j * Column_Width)

            .Top = lvarY

            .Width = 0

            .Height = ((i - 1) * Row_Height)

        End With

Next j

 

 

End Sub

 

 

Sub delete_lines()

 

 

For Each Symbol In ThisDisplay.Symbols

    If Symbol.Type = 1 Then

        Symbols.Remove (Symbol.Name)

    End If

Next

 

 

End Sub

Outcomes