Results 1 to 21 of 21

Thread: copy and paste

  1. #1
    Guest

    Talking

    anyone knows how to copy picture or text and so, we can use ctrl+v paste on word or excel?

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Huh?

  3. #3
    Guest

    Talking

    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

  4. #4
    Lively Member
    Join Date
    Aug 2000
    Location
    Posts
    105

    maybe

    try to use sendkeys()

  5. #5
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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.

  6. #6
    Guest

    Talking

    HOw about picture?
    and how can i copy the data in a grid and paste it to excel or other grid?

  7. #7
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    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 :

  8. #8
    Guest

    Talking

    we can highlight some cells (a portion of it) , can we just copy those, instead of the whole grid?

  9. #9
    Guest

    Talking

    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?

  10. #10
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    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 :

  11. #11
    Guest

    Talking

    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

  12. #12
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    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 :

  13. #13
    Guest

    Talking

    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

  14. #14
    Guest

    Talking

    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

  15. #15
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    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 :

  16. #16
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    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.

  17. #17
    Guest

    Talking

    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?

  18. #18
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    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.

  19. #19
    Addicted Member
    Join Date
    Aug 2000
    Location
    Columbus Ohio
    Posts
    217

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

    [email protected]
    Windows XP RC2 B2526
    Visual Studio.Net Beta 2
    C++, VB, VB.Net, ASP, PHP

  20. #20
    Guest

    Talking

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

  21. #21
    Addicted Member brookema's Avatar
    Join Date
    Jul 2002
    Location
    Washington DC
    Posts
    161
    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
  •  



Click Here to Expand Forum to Full Width