Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy MsFlexGrid data from more than one cell 4

Status
Not open for further replies.

MrMajik

IS-IT--Management
Apr 2, 2002
267
0
0
I have the right mouse click menu working and am able to copy the contents of one cell of an MsFlexGrid.

Private Sub mnuCopy_Click()
Clipboard.Clear
Clipboard.SetText frmMain.MSFlexGrid2.Text
End Sub

I want to copy a range of cells so they can be pasted into Excel. Is this possible?

Thanks in advance.
MrMajik
 
Take the contents of each cell in the grid and accumulate them into a Tab delimited string.

String4Clip$ = Cell1$ & VbTab & Cell2$ & VbTab & Cell3$

Clipboard.SetText String4Clip$

Excuse my shorthand the $ suffix means the variables are Strings
 
String4Clip$ = Cell1$ & VbTab & Cell2$ & VbTab & Cell3$ & VbCrLf & _
Cell4$ & VbTab & Cell5$ & VbTab & Cell6$

should give you 2 rows of 3 cols in the target speadsheet
 
Use the textmatrix property to get the cell contents without having to change the current column or row, ie:

for r = 1 to 5
for c = 1 to 4
string = string + MSFlexGrid2.textmatrix(r,c) + vbtab
next
next



"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Thanks guys for the ideas. Both are workable so I will try both and see which one fits best. :)

Thank you,

MrMajik

There are 10 types of people in the world:
Those that understand binary and those that don't.
 


Have a look at the MSFlexGrid1.Clip method (see VB Help)

In the returned string, vbTab (Chr(9)) seperates the columns and a carriage return vbCR (Chr(13)) seperates the rows.
 
I am able to get the contents of a single cell to copy to the clipboard a hard coded range of cells to copy to the clipboard. I am unable to get a range selected by the user when the mouse is used to select a range. What I keep getting the the content of the first cell of the range selected. Is it possible to get the selected range of a FlexGrid into the clipboard when the range is selected by using the mouse?

Thank you,

MrMajik

There are 10 types of people in the world:
Those that understand binary and those that don't.
 
Well, I tried it and it works. What did you try?
 
BobRodes, Can you post a snipit of the code you got to work to copy a range of cells selected by the user?

Thank you.
 
I'll do one better than that, I'll post the whole thing! I put it in a command button:
Code:
Private Sub Command1_Click()
Clipboard.Clear
Clipboard.SetText MSFlexGrid1.Clip
End Sub

So run the form, highlight some text, push the button, go to an excel spreadsheet and hit paste. That will prove it's in the clipboard.

HTH

Bob
 
Bob,

This is what I had:
Clipboard.SetText frmMain.MSFlexGrid1.Text

I never tried .Clip at the end of the line as I got frustrated with not being able to figure it out. I thought it was much more difficult than that.

Thanks for posing. Your little line of code deserves a heart-felt Thank You and a star.

Thank you :)

Steve

Thank you,

MrMajik

There are 10 types of people in the world:
Those that understand binary and those that don't.
 
You're very welcome. I just did what SBerthold suggested (he's an MVP for good reason, and he really knows this stuff very well), but with the added benefit of not being irritated at the problem. :)
 
Thanks Bob for answering that. [smile]
Would have thought that they would have investigated the VB Help files as mentioned.

You can also reverse the process:

MSFlexGrid1.Clip = Clipboard.GetText

'Assumes a range is selected and the clipboard text is in the right format. The Clip method will insert then what it can, as far as it can:
 
<Would have thought that they would have investigated the VB Help files as mentioned.

Well, that's what I did. Steve was getting mad, or I'm sure he would have too. As we all know, the concepts "angry programmer" and "bull in china shop" are strongly analogous.
 
>As we all know, the concepts "angry programmer" and "bull in china shop" are strongly analogous.

I like that comparison. So do the stores where I buy my keyboards and mice.

We've all been there before, and will be again.

Therefore, what seems simply obvious to others, may be not as easily obvious to me, because of frustration, or simply because at the moment I'm seeing so many trees, I just cannot find the forest.
In this sense, it cannot then be right to get impatient with someone for not seeing the forest...and then turn around and tell them to look for the trees if they want to find the forest! I've seen this in several threads, some already gone, and I am also guilty of it.
 
Anger, frustration, anxiety which becomes an annoyance is something that is a part of this. The solution to this problem was so simple I could not see it. The beauty of it is I now have another tool in my mental toolbox that I will keep.

I love this place :)

Steve
 
<another tool in my mental toolbox

Let's call it the "getting up and leaving" tool. [lol]

Interestingly, I find the same thing in my piano practice. I might go over and over a passage, not get it, get mad, whatever, but if I go take a walk or something and come back to it a few hours later, very often the problem will seem to solve itself on its own. The physical fatigue component in that has got to be a factor that isn't part of programming, but still it seems like the same thing going on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top