[RESOLVED] excel to flexgrid
I have posted a similar question a while back. I have since found some code in the forum that looks like what I need to import data from a worksheet into flexgrid. I think it was posted by Si-the-geek.
I have tested it in a userform (userform has a flexgrid and a command button). The worksheet I want to access sits within this excel workbook. The code I am using is;
Code:
Private Sub ExcelToFlexgrid()
Clipboard.Clear
With Application.Workbooks("Book1.xls").Worksheets("Sheet1")
.Range("A1:F7").Copy 'Set selection to Copy
End With
With MSFlexGrid1
.Redraw = False 'Dont draw until the end, so we avoid that flash
.row = 0 'Paste from first cell
.Col = 0
.RowSel = .Rows - 1 'Select maximum allowed (your selection shouldnt be greater than this)
.ColSel = .Cols - 1
.Clip = Replace(Clipboard.GetText, vbNewLine, vbCr) 'Replace carriage return with the correct one
.Col = 1 'Just to remove that blue selection from Flexgrid
.Redraw = True 'Now draw
End With
xlObject.DisplayAlerts = False 'To avoid "Save woorkbook" messagebox
'Close Excel
xlWB.Close
xlObject.Application.Quit
Set xlWB = Nothing
Set xlObject = Nothing
End Sub
Private Sub Command1_Click()
Call ExcelToFlexgrid
End Sub
I have 2 problems, when I run the code it comes up with the following error; runtime error 424 object required and highlights Clipboard.Clear
I have referenced the microsoft excel object library but it doesn't make a difference.
Secondly, how do I get it to import all data rather than a specified range (the number of rows will vary)
Many thanks in advance
Re: [RESOLVED] excel to flexgrid