1 Replies - 843 Views - Last Post: 10 October 2013 - 04:19 AM Rate Topic: -----

#1 prashanthi_poonam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-August 13

copy data in clipboard from mshflexgrid

Posted 09 October 2013 - 10:57 PM

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
With MSHFlexGrid1
'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)
End With
With xlObject.ActiveWorkbook.ActiveSheet
.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
End With
' 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
appExcel.Workbooks.Add
' 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)
Next lngCols
Next lngRows
' Change the save path as needed....
'appExcel.ActiveWorkbook.SaveAs App.Path '& "\flexgrid.xls"
appExcel.Quit
Set appExcel = Nothing
End Sub

Private Sub Command1_Click()
FlexToExcel
End Sub

Is This A Good Question/Topic? 0
  • +

Replies To: copy data in clipboard from mshflexgrid

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3190
  • View blog
  • Posts: 10,681
  • Joined: 12-December 12

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.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1