View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
royUK[_37_] royUK[_37_] is offline
external usenet poster
 
Posts: 1
Default How do I call up a line of code that references a cell/range in theactive workbook workbook where I am running my macro from?


You don't need to select/activate the workbooks. Is the code in the
activeworkbook & you want to copy B2 from workbook1.xls?


Code:
--------------------

Option Explicit

Function IsOpen(wbName As String) As Boolean
Dim Wb As Workbook
On Error Resume Next
Set Wb = Workbooks(wbName)
If Err = 0 Then IsOpen = True
End Function

Sub copyRange()
Dim sFilName As String
sFilName = "WorkBook1.xls"

If Not IsOpen(sFilName) Then Workbooks.Open _
("C:" & sFilName & ".xls")
Workbooks(sFilName).Sheet1.Cells(2, 2).Copy _
ThisWorkbook.Sheet1.Cells(2, 2)

End Sub

--------------------


--
royUK

Hope that helps, RoyUK
For tips & examples visit my 'web site
' (http://www.excel-it.com)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=28001