Last active
February 6, 2019 13:33
-
-
Save dzzie/430a9daf59290bfa78fb4513d6d4e53d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'copies all the data from a flexgrid into well formatted rows for text display | |
'use delimiter to skip padding and have in csv type format, | |
'delimiter not checked for in data | |
Public Sub FlexGridCopy(fg As msflexgrid, Optional delimiter = Empty) | |
Dim colWidths() As Long | |
ReDim colWidths(fg.Cols) | |
Dim rows() As String | |
Dim fields() As String | |
Dim d As String | |
If Len(delimiter) = 0 Then | |
For c = 0 To fg.Cols - 1 | |
For r = 0 To fg.rows - 1 | |
maxwidth = Len(fg.TextMatrix(r, c)) | |
If maxwidth > colWidths(c) Then colWidths(c) = maxwidth | |
Next | |
Next | |
End If | |
For r = 0 To fg.rows - 1 | |
Erase fields | |
For c = 0 To fg.Cols - 1 | |
d = fg.TextMatrix(r, c) | |
If Len(delimiter) = 0 Then | |
d = d & Space(colWidths(c) - Len(d) + 2) | |
Else | |
d = d & delimiter | |
End If | |
push fields, d | |
Next | |
push rows, Join(fields, "") | |
Next | |
Clipboard.Clear | |
Clipboard.SetText Join(rows, vbCrLf) | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment