|
-
Oct 18th, 2000, 04:19 PM
#1
anyone knows how to copy picture or text and so, we can use ctrl+v paste on word or excel?
-
Oct 18th, 2000, 04:22 PM
#2
-
Oct 18th, 2000, 04:27 PM
#3
copy the picture , something like ctrl +C in own vb program then we can go to word or excel and then use CTRL+ V paste it, i think is something about clib
-
Oct 18th, 2000, 04:30 PM
#4
Lively Member
-
Oct 18th, 2000, 04:31 PM
#5
if it's text its:
Clipboard.SetData "Your Text Here", or
Clipboard.SetData yourStringHere
that should take along any formatting to the text as well.
-
Oct 18th, 2000, 04:33 PM
#6
HOw about picture?
and how can i copy the data in a grid and paste it to excel or other grid?
-
Oct 18th, 2000, 04:43 PM
#7
Here is how you can copy Selected Data from MS Flex Grid to the clipboard.
Code:
Dim startCol As Integer
Dim endCol As Integer
Dim startRow As Integer
Dim endRow As Integer
Dim i As Integer
Dim j As Integer
Dim strData As String
Dim temp As Integer
With MSFlexGrid1
startCol = .Col
endCol = .ColSel
If startCol > endCol Then
temp = endCol
endCol = startCol
startCol = temp
End If
startRow = .Row
endRow = .RowSel
strData = ""
For i = startRow To endRow
For j = startCol To endCol
strData = strData & .TextMatrix(i, j) & " "
Next j
strData = strData & vbCrLf
Next i
End With
'MsgBox strData
Clipboard.Clear
Clipboard.SetText (strData)
MsgBox "Data has been copied to the Clipboard", vbInformation
To copy Picture to the Clipboard use the following code
Clipboard.SetData Picture1.Picture
Hope this helps
Danial
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Oct 18th, 2000, 04:48 PM
#8
we can highlight some cells (a portion of it) , can we just copy those, instead of the whole grid?
-
Oct 18th, 2000, 04:54 PM
#9
Danial:
Private Sub Command1_Click()
MSFlexGrid1.Rows = 3
MSFlexGrid1.Cols = 3
MSFlexGrid1.TextMatrix(1, 1) = "hi"
MSFlexGrid1.TextMatrix(2, 2) = "what?"
End Sub
Private Sub Command2_Click()
your code
end sub
then i go to excel and paste... it doesn't work good...
want to give a hand?
-
Oct 18th, 2000, 05:04 PM
#10
Hi Dragonyian,
Try this code, i just modified it so that u can copy it to an excel file, infact my code will copy the Data from selected Cells to an Excel file .
Hope this helps.
Danial
Code:
'Add a Reference to "Microsoft Excel xx Object Library".
Function copyData()
Dim startCol As Integer
Dim endCol As Integer
Dim startRow As Integer
Dim endRow As Integer
Dim i As Integer
Dim j As Integer
Dim strData As String
Dim temp As Integer
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
' Assign object references to the variables. Use
' Add methods to create new workbook and worksheet
' objects.
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets.Add
With MSFlexGrid1
startCol = .Col
endCol = .ColSel
If startCol > endCol Then
temp = endCol
endCol = startCol
startCol = temp
End If
startRow = .Row
endRow = .RowSel
strData = ""
For i = startRow To endRow
For j = startCol To endCol
xlSheet.Cells(i, j).Value = .TextMatrix(i, j)
Next j
Next i
End With
xlSheet.SaveAs "C:\test.xls"
MsgBox "The selected data has been copied to the file C:\test.xls", vbInformation
' Close the Workbook
xlBook.Close
' Close Microsoft Excel with the Quit method.
xlApp.Quit
' Release the objects.
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
End Function
Private Sub Command1_Click()
Call copyData
End Sub
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Oct 18th, 2000, 05:20 PM
#11
danial
first, thanks reply for me
i try to avoid open excel, because some machine might not have excel, so i modify your codes
and insert a excel sheet objext
strData = ""
For i = startRow To endRow
For j = startCol To endCol
Sheet1.Cells(i, j).Value = .TextMatrix(i, j)
Next j
Next i
but it doesn't take the sheet1.cells function, wonder why?
again, thanks
-
Oct 18th, 2000, 07:01 PM
#12
Hi,
I am a little bit confused, i am not sure what exactly you are trying to do.
My first Pice of code copies the Selected Cells of an MSFlexGrid to the Clipboard. You need to select some cells/rows/columns before u call the function.
But the problem with this method is that the data copied to the Clipboard is a long String and when you paste this to Excel it only pastes it into one cell.
Thats why i gave you the second method which saves the selectd Data to an Excel file.
but it doesn't take the sheet1.cells function, wonder why?
You need to declare Sheet one as an Excel Worksheet
e.g.
Code:
Dim Apps As Excel.Application
Dim Sheet1 As Excel.Worksheet
Dim Book As Excel.Workbook
Set Apps = New Excel.Application
Set Book = Apps.Workbooks.Add
Set Sheet1 = Book.Worksheets.Add
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Oct 18th, 2000, 07:28 PM
#13
Sorry to catch up so late....
what iwas trying to do is copy the data on the grid... so, the user can paste it later, the user might paste it to excel (but not necessary), because the user might paste it back to VB GRID .
I avoid to use open excel object , because some machine might not having execl installed.... so i try to use Excel OCX, .... there is a Sheet ocx we can use in vb... but somehow, it can not work.... like the problem i mentioned above..
Ya, you are right, clipboard write them as string, so, it will not take empty cell.... wonder any way to do that
Once again, thanks for the hint that you gave
-
Oct 22nd, 2000, 10:46 PM
#14
Anyone knows how can we copy the contains in the fixed rows or column?
Please i tried to use the codes above but can't copy the data from teh fixed rows or cols....
Help ie appreciated
-
Oct 23rd, 2000, 05:00 AM
#15
Hi,
Here is how you can copy the contents of fixed column from a MSFlexGrid Control.
Hope this helps.
Danial
Code:
Private Sub Command1_Click()
Dim sString As String
Dim iStart As Integer
Dim iEnd As Integer
iStart = MSFlexGrid1.FixedCols
iEnd = MSFlexGrid1.Cols - 1
sString = ""
For i = iStart To iEnd
sString = sString & " " & MSFlexGrid1.TextMatrix(0, i)
Next i
'MsgBox sString
Clipboard.Clear
Clipboard.SetText (sString)
End Sub
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Oct 23rd, 2000, 06:48 AM
#16
Frenzied Member
I'm sorry people but why are you all using Clipboard.Settext when he want's to place pictures?
Use
Clipboard.SetData Picture1.Picture
instead.
it wouldn't be that hard to set the focus to Excel and then sendkeys(^V, True) to it.
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 23rd, 2000, 10:23 AM
#17
Jop:
I am not sure the method that you are referring to... can you make a small example? then everyone can try your method.. as i thought settext is what others are using now..thanks.....
And how about pasting? we talk about copying and hope can we paste thing into Grid?
-
Oct 23rd, 2000, 10:41 AM
#18
Frenzied Member
hmmm everybody is using settext but you'd better use SetData
hmmm I made a simple example with notepad, you can change it to excel and the grid..
If you need help finding excel, just ask 
Code:
'Put a commandbutton and a textbox on your form
Private Sub Command1_Click()
Shell "notepad.exe", vbNormalFocus
Clipboard.SetText Text1.Text
SendKeys "^V", True
End Sub
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 23rd, 2000, 11:05 AM
#19
Addicted Member
You forget
Actually CTRL+C and CTRL+V are built into windows soooooo they work automatically in itself. Unless you manually want to send that data.
-
Oct 23rd, 2000, 11:36 AM
#20
Jop , Chris_SE and others
Thanks for the reply....
I am using the Grid Control.... so it is kind of messy around here... i try to copy stuff from excel and paste them to Grid...
But i don't know how can we send them to each cells.. the example from MSDN or other articles are talking about single cell.... so not sure i can do it ....
-
Aug 9th, 2002, 02:35 PM
#21
Addicted Member
Originally posted by Jop
hmmm everybody is using settext but you'd better use SetData
hmmm I made a simple example with notepad, you can change it to excel and the grid..
If you need help finding excel, just ask 
Code:
'Put a commandbutton and a textbox on your form
Private Sub Command1_Click()
Shell "notepad.exe", vbNormalFocus
Clipboard.SetText Text1.Text
SendKeys "^V", True
End Sub
Anyone have any idea why this will work if you Shell to Notepad, but will not work if you shell to Word?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|