Consulting

Results 1 to 3 of 3

Thread: VBA: GetObject / Copy and Past is bringing only 255 characters

  1. #1
    VBAX Regular Buddy's Avatar
    Joined
    Sep 2017
    Posts
    10
    Location

    Exclamation VBA: GetObject / Copy and Past is bringing only 255 characters

    Hi, Everyone!

    I'm simply tring to get a cell content from an unsaved workbook (Book1) through GetObject function, plus Copy and Paste. But as the content of the cell is a very long string, I only get a piece of it (until characters 255).

    The code I'm using is:

    Dim oApp As Application
    Dim oWb As Workbook
        
    Set oWb = GetObject("Book1")
    Set oApp = oWb.Parent
        
    oWb.ActiveSheet.Range("A1").Copy
    Workbooks("Workbook1.xlsm").Worksheets("Sheet1").Range("A1").PasteSpecial Paste:=xlPasteFormats
    
    oWb.Close False
    oApp.Quit
    When I copy and paste manually, everything goes OK. The entire string comes. But through VBA I'm getting just the first 255 characters.

    Anyone knows any way to overcame this?

  2. #2
    VBAX Regular Buddy's Avatar
    Joined
    Sep 2017
    Posts
    10
    Location
    Nevermind. I just replace the "Paste:=xlPasteFormats" for "Paste:=xlPasteValues" and it worked! Thanks anyway.

  3. #3
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    You don't even need to copy and paste - just assign the value directly:

    Workbooks("Workbook1.xlsm").Worksheets("Sheet1").Range("A1").value = oWb.ActiveSheet.Range("A1").Value
    Be as you wish to seem

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •