Solved

VB6 paste clipboard into MSHFlexgrid

Posted on 2013-06-02
2
1,331 Views
Last Modified: 2013-06-02
Hi again

I have this script that past all values into a column in my MSHFlexgrid

Dim lRows As Long
    Dim sText As String
      sText = Clipboard.GetText
      lRows = UBound(Split(sText, vbCr)) + 1
      With MSHFlexGrid2
        .Rows = .FixedRows + lRows
        .Row = .FixedRows
        .Col = .FixedCols  '(or whatever value you like)
        .RowSel = .Rows - 1
        .Clip = Replace(sText, vbLf, "")
      End With

Open in new window


But this is if i copy value from a same column.

I would like to now copy into clipboard data from 2 columns and it would paste it into 2 columns in my MSHFlexgrid.

Ex:
if i copy this below from my excel file:
Col1          Col2
1               a
2               b
3               c
4               d
5               e


When i paste into my MSHFlexgrid it will paste it into 2 columns:
1               a
2               b
3               c
4               d
5               e


How can i do that?

thanks again
0
Comment
Question by:Wilder1626
2 Comments
 
LVL 15

Accepted Solution

by:
eemit earned 500 total points
ID: 39215240
Try this:

  Dim nFixedRows As Long
  Dim nFixedCols As Long
  Dim nRows As Long
  Dim nCols As Long

  nFixedRows = 1
  nFixedCols = 0

  sText = Clipboard.GetText

  nRows = UBound(Split(sText, vbCr)) + 1
  
  'Dim vRows As Variant
  'vRows = Split(sText, vbCr)
  'nCols = UBound(Split(vRows(0), vbTab)) + 1
  nCols = UBound(Split(Split(sText, vbCr)(0), vbTab)) + 1
  'Debug.Print nCols

  With MSHFlexGrid2
      .FixedRows = nFixedRows
      .FixedCols = nFixedCols
        
      .Rows = .FixedRows + nRows
      .Cols = .FixedCols + nCols
      .Row = .FixedRows
      .Col = .FixedCols  '(or whatever value you like)
        
      .RowSel = .Rows - 1
      .ColSel = .Cols - 1
        
      .Clip = Replace(sText, vbLf, "")
  End With

Open in new window

0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 39215246
Thanks for your help, this is perfect
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

808 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