Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1497
  • Last Modified:

VB6 paste clipboard into MSHFlexgrid

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
Wilder1626
Asked:
Wilder1626
1 Solution
 
eemitCommented:
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
 
Wilder1626Author Commented:
Thanks for your help, this is perfect
0

Featured Post

Independent Software Vendors: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now