Solved

Copy list view contents

Posted on 2001-06-28
8
1,037 Views
Last Modified: 2008-03-17
I just want to copy all contents with the settings(col,rows) in the clipboard so that i can paste it in excel for printout or for saving that in a file.
0
Comment
Question by:asmahmood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6234480
This message should understood as answer.
(Because of limitations in this community its only a comment.)
-----------------------------------------------------------
This example uses the SetText method to copy text from a text box to the Clipboard. To try this example, paste the code into the Declarations section of a form with a text box named Text1, and then press F5 and click the form.

Private Sub Form_Click()
Const CF_TEXT = 1   ' Define bitmap format.
Dim I, Msg, Temp   ' Declare variables.
On Error Resume Next   ' Set up error handling.
Msg = "Type anything you like into the text box below."
Text1.Text = InputBox(Msg)   ' Get text from user.
Msg = "Choose OK to copy the contents of the text box "
Msg = Msg & "to the Clipboard."
MsgBox Msg   ' Display message.
Clipboard.Clear   ' Clear Clipboard.
Clipboard.SetText Text1.Text   ' Put text on Clipboard.
If Clipboard.GetFormat(CF_TEXT) Then
   Text1.Text = ""   ' Clear the text box.
   Msg = "The text is now on the Clipboard. Choose OK "
   Msg = Msg & "to copy the text from the Clipboard back "
   Msg = Msg & "to the text box."
   MsgBox Msg   ' Display message.
   Temp = Clipboard.GetText(CF_TEXT)   ' Get Clipboard text.
   For I = Len(Temp) To 1 Step -1   ' Reverse the text.
      Text1.Text = Text1.Text & Mid(Temp, I, 1)
   Next I
Else
   Msg = "There is no text on the Clipboard."
   MsgBox Msg   ' Display error message.
End If
End Sub

;o)
WoK
0
 
LVL 3

Accepted Solution

by:
casassus earned 50 total points
ID: 6234587
To copy the content of a listview in the clipboard, you can try this.

dim I as integer
dim J as integer
dim strContents as string

strContents=""
for i= 1 to MyListView.listItems.count
 strContents=strContents + MyListView.listItems(i)
 for j=1 to MyListView.columnheaders.count-1
  strContents=strContents+vbtab+MyListView.listItems(i).subitems(j)
 next j
 strContents=strContents+vbcrlf
next i

clipboard.clear
clipboard.settext strContents
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6235054
interesting...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6237283
Hi asmahmood,
Note:
You can do your task without the clipboard by using
OLE Automation
You must link the "Microsoft Excel 8.0 Object Library" to your project file (IDE: Menu Project\Links)!
And then put this in a VB module and call the main sub:
-----------------------------------------------------------
Private m_objExcel As Excel.Application

' Comments  : Starts an instance of Excel
' Parameters: fVisible - True to make Excel visible
' Returns   : Nothing
Public Sub StartExcel(fVisible As Boolean)
On Error GoTo PROC_ERR
 
Set m_objExcel = New Excel.Application
m_objExcel.Visible = fVisible
 
PROC_EXIT:
  Exit Sub
 
PROC_ERR:
  MsgBox "Error: " & Err.Number & ". " & Err.Description, , _
    "StartExcel"
  Resume PROC_EXIT

End Sub

Public Sub FillExcel()
dim I as integer
dim J as integer
dim strContents as string

strContents=""
for i= 1 to MyListView.listItems.count
m_objWorkbook.ActiveWorkbook.ActiveSheet.Cells(i,0).Value = MyListView.listItems(i)
for j=1 to MyListView.columnheaders.count-1
m_objWorkbook.ActiveWorkbook.ActiveSheet.Cells(i,j).Value = MyListView.listItems(i).subitems(j)
next j
next i
End Sub

Public Sub Main()
  StartExcel(True)
  FillExcel
End Sub

-----------------------------------------------------------

Greeting
WoK
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6237288
Sorry the lines:
for i= 1 to MyListView.listItems.count
m_objWorkbook.ActiveWorkbook.ActiveSheet.Cells(i,0).Value = MyListView.listItems(i)
for j=1 to MyListView.columnheaders.count-1
m_objWorkbook.ActiveWorkbook.ActiveSheet.Cells(i,j).Value = MyListView.listItems(i).subitems(j)

Must be:
for i= 1 to MyListView.listItems.count
m_objExcel.ActiveWorkbook.ActiveSheet.Cells(i,0).Value = MyListView.listItems(i)
for j=1 to MyListView.columnheaders.count-1
m_objExcel.ActiveWorkbook.ActiveSheet.Cells(i,j).Value = MyListView.listItems(i).subitems(j)


Bye
WoK
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6237583
(I have checked the code)
The lines:
for i= 1 to MyListView.listItems.count
m_objExcel.ActiveWorkbook.ActiveSheet.Cells(i,0).Value = MyListView.listItems(i)
for j=1 to MyListView.columnheaders.count-1
m_objExcel.ActiveWorkbook.ActiveSheet.Cells(i,j).Value = MyListView.listItems(i).subitems(j)

must be:
for i= 1 to MyListView.listItems.count
m_objExcel.ActiveWorkbook.ActiveSheet.Cells(i,1).Value = MyListView.listItems(i)
for j=1 to MyListView.columnheaders.count-1
m_objExcel.ActiveWorkbook.ActiveSheet.Cells(i,j + 1).Value = MyListView.listItems(i).subitems(j)


Bye
WoK
0
 

Author Comment

by:asmahmood
ID: 6237656
Thank u all for answering me but there was some problem with expert exchange server yesterday and i want the answer as early as possible becuse it was not too big problem so create another routine which was same like CASASSUS's comments so i did it but thanks WolfgangKoening i will definately try ur way if it works! but now i am doing my work with CASASSUS's comment so thnks again
0
 

Author Comment

by:asmahmood
ID: 6237660
it works thanks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

691 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