View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Tushar Mehta[_8_] Tushar Mehta[_8_] is offline
external usenet poster
 
Posts: 11
Default copying from another instance of excel

Assuming you have a controlled environment (i.e., the other instance of XL is
not automagically instantiated), the following tested code will do the job.

Option Explicit

Sub testIt()
#Const doCleanup = False
Dim otherXL As Application, thisXLWB As Workbook, _
otherXLWB As Workbook
Set otherXL = CreateObject("excel.application")
otherXL.Visible = True
Set otherXLWB = otherXL.Workbooks.Add()
otherXLWB.Worksheets(1).Range("a1").Resize(10, 3).Formula = _
"=row()/column()"
Set thisXLWB = Application.Workbooks.Add()
'...
otherXLWB.Worksheets(1).Range("a1").CurrentRegion. Copy
thisXLWB.Sheets(1).Range("a1").PasteSpecial xlValues
'...
#If doCleanup Then
otherXLWB.Close False
otherXL.Quit
Set otherXLWB = Nothing
Set otherXL = Nothing
#End If
End Sub


"Paul" wrote:

Thanks Bob,

I am running two instances of excel, i.e. both are running
on the same machine. one is book1.xls and the other is
book2.xls. Have corrected the quotes problem, but still
cannot get it to work. Aslo have tried to set a variable
to the value --- also with no luck.


-----Original Message-----
Do you really mean separate instances of Excel or

separate workbooks? If the
latter, you need to enclose the worksheet name in quotes,

and you don't need
Application, it is implicit.

Workbooks("book2").Worksheets("Sheet1").Range("a1 ").Value

= _
Workbooks("book1").Worksheets("Sheet1").Range("a1 ").Value


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Paul" wrote in

message
...
Is it possible to copy cell contents between instances

of
excel??

I cannot get the following code to work. Can anyone

tell
me why?

Application.Workbooks("book2.xls").Worksheets

(Sheet1).Range
("a1").Value = Application.Workbooks
("book1.xls").Worksheets(Sheet1).Range("a1").Va lue



.