PDA

View Full Version : VBA: GetObject / Copy and Past is bringing only 255 characters



Buddy
12-14-2018, 03:19 PM
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?

Buddy
12-14-2018, 04:03 PM
Nevermind. I just replace the "Paste:=xlPasteFormats" for "Paste:=xlPasteValues" and it worked! Thanks anyway.

Aflatoon
12-17-2018, 06:21 AM
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