?
Solved

VB6 - Copy to clipboard all cells including headers row 0

Posted on 2014-04-05
8
Medium Priority
?
340 Views
Last Modified: 2014-04-05
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
Comment
Question by:Wilder1626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39980474
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
 
LVL 11

Author Comment

by:Wilder1626
ID: 39980484
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
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39980580
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
Industry Leaders: 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!

 
LVL 11

Author Comment

by:Wilder1626
ID: 39980615
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
 
LVL 48

Accepted Solution

by:
Martin Liss earned 2000 total points
ID: 39980631
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
 
LVL 11

Author Comment

by:Wilder1626
ID: 39980660
wow, this is more then what i was wishing for

Thank you so much for your help
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 39980661
thanks again for your help
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39980679
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question