I'm running two separate instances of Excel and I'm trying to copy data from a Range in one workbook to the other.
I have this code:
Sub CopyValues()
Dim xlApp As Excel.Application
Set xlApp = GetObject(, "Excel.Application")
Dim Src As Range
Dim Dst As Range
Set Src = xlApp.ActiveSheet.Range("A1:A9")
Set Dst = Workbooks("Book1.xlsm").Worksheets("Sheet1").Range("A1:A9")
Src.Copy Dst
End Sub
It doesn't return any errors but it doesn't copy the values, Also tried this for the last line
Src.Value = Dst.Value
Still does nothing
My VBA skills are not so good, just started learning it 2 weeks ago.
Unfortunately, there is no easy way to get formulas from one instance of Excel to another. The best you can do is the following: In the source workbook, select a single cell that you want to copy. Press F2. Excel switches to Edit mode. While still in Edit mode, select everything in the cell (the entire formula). Press Ctrl+C.
You can't even use Paste Special from the Edit menu to paste formulas; that isn't an option when working with two instances. Unfortunately, there is no easy way to get formulas from one instance of Excel to another.
Within the Excel window, use the mouse to arrange the two workbooks so one is on each monitor. Since you are using a single instance of Excel—even though it extends across two monitors—you can now cut, copy, and paste as you normally would. ExcelTips is your source for cost-effective Microsoft Excel training.
You can then work with both workbooks onscreen at the same time. One thing you'll notice, however, is that copying information from one instance of Excel to another works differently than when you copy within the same instance.
If you want to avoid using the clipboard, and assuming that your handle to the other instance of Excel (xlApp) is correct, then you should be able to use an array to get and set your data.
Sub CopyValues()
Dim xlApp As Excel.Application
Dim Src As Range
Dim Dst As Range
Dim Vals() as Variant
Set xlApp = GetObject(, "Excel.Application")
Set Src = xlApp.ActiveSheet.Range("A1:A9")
Set Dst = Workbooks("Book1.xlsm").Worksheets("Sheet1").Range("A1:A9")
Vals = Src
Dst.Value = Vals
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With