K
Keith Norris
Hi Helpers,
I'm trying to compare values from one spreadsheet to another and highligh
the cells in the original if they match. I've tried many things with the
range object but it doesn't work. I've narrowed it down to what I think the
problem is.
If I reference more than one workbook, it will fail. If I only reference
the original workbook, it works fine. Can you explain to me why this is?
Here is the narrowed down code. This code will work fine but if I uncomment
the reference to the other workbook it fails. Why is that? What can I do to
allow this? I'm using Excel 2003 but I would think 2007 can handle it the
same way.
Dim objBook As Workbook
Dim objSheet As Worksheet
Dim objOtherBook As Workbook
Dim objOtherSheet As Worksheet
Dim objShell As Object
Dim strPath As String
strRange = "A2:F2"
Set objBook = ThisWorkbook
Set objSheet = objBook.Sheets("Sheet1")
Set objShell = CreateObject("wscript.shell")
strPath = objShell.specialfolders("MyDocuments") & "\Referrals for Exam
and AM\Transmittals\"
'Set objOtherBook = Excel.Workbooks.Open(strPath & "2009 EFDS StartUp
Distribution List")
'Set objOtherSheet = objOtherBook.Sheets("TNSNames and WMS")
objSheet.Names.Add Name:="Data", RefersTo:="=" & strRange
objSheet.Range("Data").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
I'm trying to compare values from one spreadsheet to another and highligh
the cells in the original if they match. I've tried many things with the
range object but it doesn't work. I've narrowed it down to what I think the
problem is.
If I reference more than one workbook, it will fail. If I only reference
the original workbook, it works fine. Can you explain to me why this is?
Here is the narrowed down code. This code will work fine but if I uncomment
the reference to the other workbook it fails. Why is that? What can I do to
allow this? I'm using Excel 2003 but I would think 2007 can handle it the
same way.
Dim objBook As Workbook
Dim objSheet As Worksheet
Dim objOtherBook As Workbook
Dim objOtherSheet As Worksheet
Dim objShell As Object
Dim strPath As String
strRange = "A2:F2"
Set objBook = ThisWorkbook
Set objSheet = objBook.Sheets("Sheet1")
Set objShell = CreateObject("wscript.shell")
strPath = objShell.specialfolders("MyDocuments") & "\Referrals for Exam
and AM\Transmittals\"
'Set objOtherBook = Excel.Workbooks.Open(strPath & "2009 EFDS StartUp
Distribution List")
'Set objOtherSheet = objOtherBook.Sheets("TNSNames and WMS")
objSheet.Names.Add Name:="Data", RefersTo:="=" & strRange
objSheet.Range("Data").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With