Solved

VB6 - Copy to clipboard all cells including headers row 0

Posted on 2014-04-05
8
330 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

867 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

16 Experts available now in Live!

Get 1:1 Help Now