we are trying to export mshflexgrid data into excel with the following code. but data is not getting copied into the clipboard. we tried using the same code in different computer having same platform.it is working over there. but not on the pc on which we are working.
Private Sub FlexToExcel()
Dim xlObject As Excel.Application
Dim xlWB As Excel.Workbook
Set xlObject = New Excel.Application
'This Adds a new woorkbook, you could open the workbook from file also
Set xlWB = xlObject.Workbooks.Add
Clipboard.Clear 'Clear the Clipboard
'Select Full Contents (You could also select partial content)
.Col = 0 'From first column
.Row = 0 'From first Row (header)
.ColSel = .Cols - 1 'Select all columns
.RowSel = .Rows - 1 'Select all rows
Clipboard.SetText .Clip 'Send to Clipboard this command we think is not sending data to the clipboard)
.Range("g1") = "New Horizon Public School,Airoli"
.Range("g2") = " Report"
.Range("A6").Select 'Select Cell A1 (will paste from here, to different cells)
.Paste 'Paste clipboard contents
' This makes Excel visible
xlObject.Visible = True
' Requires a reference to the Microsoft Excel x.x Object Library.
Dim appExcel As Excel.Application
Dim lngRows As Long
Dim lngCols As Long
Set appExcel = New Excel.Application
' Alter For...Next loops as needed if you use fixed rows and/or columns on your grid.
For lngRows = 0 To MSHFlexGrid1.Rows - 1
For lngCols = 0 To MSHFlexGrid1.Cols - 1
appExcel.Cells(lngRows + 1, lngCols + 1) = MSHFlexGrid1.TextMatrix(lngRows, lngCols)
' Change the save path as needed....
'appExcel.ActiveWorkbook.SaveAs App.Path '& "\flexgrid.xls"
Set appExcel = Nothing
Private Sub Command1_Click()
Page 1 of 1
1 Replies - 1220 Views - Last Post: 10 October 2013 - 04:19 AM
Replies To: copy data in clipboard from mshflexgrid
Re: copy data in clipboard from mshflexgrid
Posted 10 October 2013 - 04:19 AM
General debugging advice:
- If it doesn't work on one specific computer then list the differences (Windows' versions, etc.) between the computers.
- After the application finishes use paste to see what is on the clipboard.
- Use the extensive debugging features of VB6 to step through your code.
Page 1 of 1