Results 1 to 14 of 14

Thread: Get data from Excel ?

  1. #1

    Thread Starter
    Addicted Member Tengkorak's Avatar
    Join Date
    Nov 2006
    Posts
    240

    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

  2. #2
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    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?
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  4. #4

    Thread Starter
    Addicted Member Tengkorak's Avatar
    Join Date
    Nov 2006
    Posts
    240

    Re: Get data from Excel ?

    Quote Originally Posted by seenu_1st View Post
    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.

  5. #5

    Thread Starter
    Addicted Member Tengkorak's Avatar
    Join Date
    Nov 2006
    Posts
    240

    Re: Get data from Excel ?

    Quote Originally Posted by westconn1 View Post
    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.

  6. #6
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    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
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  7. #7

    Thread Starter
    Addicted Member Tengkorak's Avatar
    Join Date
    Nov 2006
    Posts
    240

    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

  8. #8
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: Get data from Excel ?

    Quote Originally Posted by Tengkorak View Post
    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.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  9. #9

    Thread Starter
    Addicted Member Tengkorak's Avatar
    Join Date
    Nov 2006
    Posts
    240

    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 ?

  10. #10
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    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
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  11. #11

    Thread Starter
    Addicted Member Tengkorak's Avatar
    Join Date
    Nov 2006
    Posts
    240

    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.

  12. #12
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    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.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  13. #13
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    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.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  14. #14
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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
  •  



Click Here to Expand Forum to Full Width