1. Private Sub FlexToExcel()
2. Dim xlObject As Excel.Application
3. Dim xlWB As Excel.Workbook
4.
5. Set xlObject = New Excel.Application
6.
7. 'This Adds a new woorkbook, you could open the workbook from file also
8. Set xlWB = xlObject.Workbooks.Add
9.
10. Clipboard.Clear 'Clear the Clipboard
11. With MSFlexGrid1
12. 'Select Full Contents (You could also select partial content)
13. .Col = 0 'From first column
14. .Row = 0 'From first Row (header)
15. .ColSel = .Cols - 1 'Select all columns
16. .RowSel = .Rows - 1 'Select all rows
17. Clipboard.SetText .Clip 'Send to Clipboard
18. End With
19.
20. With xlObject.ActiveWorkbook.ActiveSheet
21. .Range("A1").Select 'Select Cell A1 (will paste from here, to different cells)
22. .Paste 'Paste clipboard contents
23. End With
24.
25. ' This makes Excel visible
26. xlObject.Visible = True
27. End Sub
1. Private Sub ExcelToFlexgrid()
2. Dim xlObject As Excel.Application
3. Dim xlWB As Excel.Workbook
4.
5. Set xlObject = New Excel.Application
6. Set xlWB = xlObject.Workbooks.Open("C:\Book1.xls") 'Open your book here
7.
8. Clipboard.Clear
9. With xlObject.ActiveWorkbook.ActiveSheet
10. .Range("A1:F7").Copy 'Set selection to Copy
11. End With
12.
13. With MSFlexGrid1
14. .Redraw = False 'Dont draw until the end, so we avoid that flash
15. .Row = 0 'Paste from first cell
16. .Col = 0
17. .RowSel = .Rows - 1 'Select maximum allowed (your selection shouldnt be greater than this)
18. .ColSel = .Cols - 1
19. .Clip = Replace(Clipboard.GetText, vbNewLine, vbCr) 'Replace carriage return with the correct one
20. .Col = 1 'Just to remove that blue selection from Flexgrid
21. .Redraw = True 'Now draw
22. End With
23.
24. xlObject.DisplayAlerts = False 'To avoid "Save woorkbook" messagebox
25.
26. 'Close Excel
27. xlWB.Close
28. xlObject.Application.Quit
29. Set xlWB = Nothing
30. Set xlObject = Nothing
31. End Sub