Solved

VB6 - Copy to clipboard all cells including headers row 0

Posted on 2014-04-05
8
334 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
  • 4
  • 4
8 Comments
 
LVL 46

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 46

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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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 46

Accepted Solution

by:
Martin Liss earned 500 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 46

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now