Solved

VB6 paste clipboard into MSHFlexgrid

Posted on 2013-06-02
2
1,296 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Determine Range to Select 5 48
vb6, excel Run-time error 1004 method 'close' of object 'workbooks' failed 7 50
How to make an ADE file by code? 11 83
vbModal 12 51
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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