Fix code - check to see if a workbook is open, if so, save changes
Let's say we want to check if a file named:
Aldridge.xls is open:
Sub jw()
Dim wb As Workbook, s As String
s = "Aldridge"
is_it_open = False
For Each wb In Workbooks
If wb.Name = s Then is_it_open = True
Next
MsgBox (is_it_open)
End Sub
--
Gary''s Student - gsnu200749
"J.W. Aldridge" wrote:
Added the "If workbook...." command to code. Not working.
Any suggestions on how to fix this?
Sub Macro7()
'
' Macro7 Macro
' Macro recorded 10/9/2007 by JW'
'
Workbooks.Open Filename:="X:\FHI Share\pcp\jeremy\NEW PCP
DATA.xls", writerespassword:="pcp123"
ActiveWorkbook.RefreshAll
ActiveWorkbook.Close SaveChanges:=True
If Workbook.Open("X:\FHI Share\pcp\jeremy\PCP DATA UPDATE.xls")
Then
ActiveWorkbook.Close SaveChanges:=True
Workbooks("X:\FHI Share\pcp\jeremy\PCP DATA UPDATE.xls").Close
End If
End Sub
|