[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

VB6 - Copy to clipboard all cells including headers row 0

Hi all,

I have this code below that copy to clipboard the selected cells.

I have 2 things i would like to add to the below script.

1- I would like to auto select all cells from the grid automatically
2- I would like to also copy to clipboard the row o with the headers.

How can i do that?

Thanks again


  With MSHFlexGrid_pref_carrier
        .Redraw = False              'Find range to copy
        min_row = .Row: max_row = .RowSel
        If min_row > max_row Then Tmp = max_row: max_row = min_row: min_row = Tmp
        min_col = .Col: max_col = .ColSel
        If min_col > max_col Then Tmp = max_col: max_col = min_col: min_col = Tmp

        my_text = ""                   'Get the text
        For i = min_row To max_row
            For j = min_col To max_col
                my_text = my_text & .TextMatrix(i, j)
                If j < max_col Then my_text = my_text & vbTab
            Next j
            If i < max_row Then my_text = my_text & vbCrLf
        Next i
        .Redraw = True
    End With

    If my_text <> "" Then
        Clipboard.Clear
        Clipboard.SetText (my_text)
    Else
        Beep
        MsgBox "Please select some text.", vbExclamation, "Nothing selected!"
    End If

Open in new window

0
Wilder1626
Asked:
Wilder1626
  • 4
  • 4
1 Solution
 
Martin LissRetired ProgrammerCommented:
This copies all the text to the clipboard without user selection.

Dim strText As String
Dim intCol As Integer
Dim intRow As Integer

With MSFlexGrid1
    For intCol = 0 To .Cols - 1
        For intRow = 0 To .Rows - 1
            strText = strText & .TextMatrix(intRow, intCol) & " "
        Next
    Next
End With
Clipboard.Clear
Clipboard.SetText strText

Open in new window

0
 
Wilder1626Author Commented:
HI

i think we are almost there.

The result you gave me gives me the 2 column of data in 1 single column.
Ex:
ASD_RUN
01:00 Mon-Sat
04:30 Sun
10:45 (B) Sat
10:45 (A) Sun-Fri
12:50 (A) Sat
20:45 Sat
20:30 Sun-Fri
23:00 (A) Sun-Thu
23:00 (B) Fri
CARRIER_ID
ROBERT
ROBERT
ROBERT
ROBERT
ROBERT
ROBERT
ROBERT
ROBERT
ROBERT



When what i want, is really each column of same row should be one beside the other

ex:
01:00 Mon-Sat       ROBERT
04:30 Sun      ROBERT
10:45 (B) Sat      ROBERT
10:45 (A) Sun-Fri      ROBERT
12:50 (A) Sat      ROBERT
20:45 Sat      ROBERT
20:30 Sun-Fri      ROBERT
23:00 (A) Sun-Thu      ROBERT
23:00 (B) Fri      ROBERT
0
 
Martin LissRetired ProgrammerCommented:
Try this. You could also change line 9 to

strText = strText & .TextMatrix(intRow, intCol) & vbTab


Dim strText As String
Dim intCol As Integer
Dim intRow As Integer

With MSFlexGrid1
    For intCol = 0 To .Cols - 1
        For intRow = 0 To .Rows - 1
            If intRow <> .Rows - 1 Then
                strText = strText & .TextMatrix(intRow, intCol) & " "
            Else
                strText = strText & .TextMatrix(intRow, intCol) & vbCrLf
            End If
        Next
    Next
End With
Clipboard.Clear
Clipboard.SetText strText

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Wilder1626Author Commented:
Looks like i'm still having some problem.

Here is what the grid looks like:
grid
When i copy ti clipboard, and when i will paste the date, it will give:

ASD_RUN      CARRIER_ID
01:00 Mon-Sat       ROBERT
04:30 Sun      ROBERT
10:45 (B) Sat      ROBERT
10:45 (A) Sun-Fri      ROBERT
12:50 (A) Sat      ROBERT
20:45 Sat      ROBERT
20:30 Sun-Fri      ROBERT
23:00 (A) Sun-Thu      ROBERT
23:00 (B) Fri      ROBERT
0
 
Martin LissRetired ProgrammerCommented:
I assume you got that result because you reversed lines 6 and 7 above but in any case try this. Change the "25" in line 6 to whatever looks best, and if column 0 could have a width greater than what you show we could calculate the value needed to show the data properly.

Dim strText As String
Dim intCol As Integer
Dim intRow As Integer

With MSFlexGrid1
    For intRow = 0 To .Rows - 1
        For intCol = 0 To .Cols - 1
            If intCol <> .Cols - 1 Then
                strText = strText & .TextMatrix(intRow, intCol) & Space(25 - Len(.TextMatrix(intRow, intCol)))
            Else
                strText = strText & .TextMatrix(intRow, intCol) & vbCrLf
            End If
        Next
    Next
End With
Clipboard.Clear
Clipboard.SetText strText

Open in new window

0
 
Wilder1626Author Commented:
wow, this is more then what i was wishing for

Thank you so much for your help
0
 
Wilder1626Author Commented:
thanks again for your help
0
 
Martin LissRetired ProgrammerCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now