-
Jun 28th, 2012, 04:50 AM
#1
Thread Starter
Addicted Member
Get data from Excel ?
Hello All,
What this is possible to get data from Clipboard(copy data) from Microsoft Excel data ?
I need to import data from copy data in sheet excel.
thanks
-
Jun 28th, 2012, 05:46 AM
#2
Re: Get data from Excel ?
do u want to paste from clipboard to excel sheet? one sheet to another sheet? what exactly u want to do? VBA or VB6?
-
Jun 28th, 2012, 06:00 AM
#3
Re: Get data from Excel ?
this looks like VBA question
excel has its own copy methods, that will work to copy (or paste) most data or other excel objects to the clipboard, but has no method to work directly with the clipboard object, as is done in vb6
i have posted an activex dll, in code bank, that will allow working with the clipboard object in VBA or VBS
http://www.vbforums.com/showthread.php?t=585616
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 1st, 2012, 09:59 PM
#4
Thread Starter
Addicted Member
Re: Get data from Excel ?
Originally Posted by seenu_1st
do u want to paste from clipboard to excel sheet? one sheet to another sheet? what exactly u want to do? VBA or VB6?
i want to copy data from excel sheet, and then paste that data in to VB6 Form, and then i will process that.
-
Jul 1st, 2012, 10:02 PM
#5
Thread Starter
Addicted Member
Re: Get data from Excel ?
Originally Posted by westconn1
this looks like VBA question
excel has its own copy methods, that will work to copy (or paste) most data or other excel objects to the clipboard, but has no method to work directly with the clipboard object, as is done in vb6
i have posted an activex dll, in code bank, that will allow working with the clipboard object in VBA or VBS
http://www.vbforums.com/showthread.php?t=585616
No, that not for VBA but for VB6.
I have Excel data, and i want to copy that data in to VB6 Form Project. This is to make user easy input data.
-
Jul 1st, 2012, 10:10 PM
#6
Re: Get data from Excel ?
this example print excel cel A1 data into form, u can change filename, sheetname cell etc...
Code:
Private Sub Form_Load()
Dim xlsApp As Object, xlsWB1 As Object, xlsWS1 As Object, Rng As Object
Dim FileName As String, StrInfo As String
FileName = "d:\a1.xls"
Set xlsApp = CreateObject("Excel.Application")
xlsApp.Visible = False
Set xlsWB1 = xlsApp.Workbooks.Open(FileName)
Set xlsWS1 = xlsWB1.worksheets("Sheet1")
With xlsWS1
StrInfo = .cells(1, 1)
Me.AutoRedraw = True
Me.Print StrInfo 'print cell data
End With
xlsWB1.Close
xlsApp.quit
'clean up
Set xlsApp = Nothing
Set xlsWB1 = Nothing
Set xlsWS1 = Nothing
End Sub
-
Jul 1st, 2012, 10:20 PM
#7
Thread Starter
Addicted Member
Re: Get data from Excel ?
thanks for your replay.
Your sample code is that we need to make one excel file a1.xls.
but, i need to copy data from excel sheet that i do not need to make a1.xls file.
i try to use Clipboard.GetText
but the result is text only and i that is hard to get valid value from real data (excel sheet data).
Do you have idea for this condition ?
thank you
-
Jul 1st, 2012, 10:28 PM
#8
Re: Get data from Excel ?
Originally Posted by Tengkorak
thanks for your replay.
Your sample code is that we need to make one excel file a1.xls.
but, i need to copy data from excel sheet that i do not need to make a1.xls file.
i try to use Clipboard.GetText
but the result is text only and i that is hard to get valid value from real data (excel sheet data).
Do you have idea for this condition ?
thank you
my sample is not to make an excel file, hav u tried that code or not? actuly it prints data of cell A1 from an excel file into the vb6 form.
-
Jul 1st, 2012, 10:43 PM
#9
Thread Starter
Addicted Member
Re: Get data from Excel ?
yes, i tried your code.
but, my question is where we get data from clipboard to process into your code ?
-
Jul 1st, 2012, 10:45 PM
#10
Re: Get data from Excel ?
where do u need to paste the clipboard data? into excel or vb6 form? see this code wil print text from clipboard into form.
Code:
Private Sub Form_Load()
Dim StrInfo As String
StrInfo = Clipboard.GetText(1)
Me.AutoRedraw = True
Me.Print StrInfo 'print text from clipboard
End Sub
-
Jul 1st, 2012, 10:45 PM
#11
Thread Starter
Addicted Member
Re: Get data from Excel ?
what i need is same like this article:
http://www.catenary.com/howto/clipbrd.html
but that for image, and i need for excel data.
-
Jul 1st, 2012, 11:43 PM
#12
Re: Get data from Excel ?
may be u need to show an excel sheet as image in form, ok add a picture box and try this code, the size of the image is depends on usedrange
Code:
Private Sub Form_Load()
Dim xlsApp As Object, xlsWB1 As Object, xlsWS1 As Object, Rng As Object
Dim FileName As String
FileName = "d:\a1.xls"
Set xlsApp = CreateObject("Excel.Application")
xlsApp.Visible = False
Set xlsWB1 = xlsApp.Workbooks.Open(FileName)
Set xlsWS1 = xlsWB1.worksheets("Sheet1")
xlsApp.displayalerts = False
xlsWS1.usedrange.Copy
Picture1.AutoRedraw = True
Picture1.AutoSize = True
Set Picture1.Picture = Clipboard.GetData(vbCFBitmap)
xlsWB1.Close savechanges:=False
xlsApp.quit
Set xlsApp = Nothing
Set xlsWB1 = Nothing
Set xlsWS1 = Nothing
End Sub
u can also set the image to form's picture.
-
Jul 2nd, 2012, 02:29 AM
#13
Re: Get data from Excel ?
u can size the image using 2 picturebox, set 1 picbox invisible, autosize = true, then use StreachBlt to draw in another picbox with its size.
-
Jul 2nd, 2012, 05:04 AM
#14
Re: Get data from Excel ?
after reading all the posts again, i am still not sure what you are trying to achive
if you want to copy an image of the excel window to a picturebox, you can use the microsoft example for printing forms, just do not print
the sample code, is at http://support.microsoft.com/default...b;en-us;161299
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
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
|