Comparing values in workbooks that are not open to my knowledge cannot be done - the workbooks need to be open. You could check to see if workbook is open and if it is not open then you could open it. The following code goes into a module in Workbook1
Sub test()
x = Sheets(1).Range("E23").Value
Windows("Workbook2.xls").Activate
y = Sheets(1).Range("H" & Cells(Rows.Count, "H").End(xlUp).Row)
If x = y Then
Windows("Workbook1.xls").Activate
ActiveWorkbook.SaveAs Filename:="C:\Files\Daily\" & ActiveWorkbook.Name & "Match.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
Else
ActiveWorkbook.SaveAs Filename:="C:\Files\Daily\" & ActiveWorkbook.Name & "NO_Match.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
End If
End Sub
To check if the second workbook is open you would use something like
On Error Resume Next
Set wbook = Workbooks("Workbook2.xls")
If wbook Is Nothing Then
Workbooks.Open Filename:="C:\Temp\Workbook 2.xls" ' change to location of workbook2.xls
Set wbook = Nothing
On Error GoTo 0
Else
Windows("Workbook2.xls").Activate
end if
Just place this macro in a module in Workbook1 = this saves workbook2 as either match or no match - you can alter the code if it is Workbook1 you want to save.
Anthony
“Confidence never comes from having all the answers; it comes from being open to all the questions.”
PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”
Bookmarks