![]() |
If Then to check if a workbook is open
I have a workbook names "Space.xls" and when a certain macro is run it goes
and pulls date from a workbook named "Moon.txt". This all works fine. However, I need a code that will look to see if "Moon.txt" is open and if it is not to skip that part of the code. -- Thanks Shawn |
If Then to check if a workbook is open
This code will open if closed or activate if open. Works from a workbook
name typed in a cell. Sub GetWorkbook() If ActiveCell.Value = "" Then Exit Sub workbookname = ActiveCell.Value On Error GoTo OpenWorkbook Windows(workbookname & ".xls").Activate Exit Sub OpenWorkbook: Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen End Sub -- Don Guillett SalesAid Software "Shawn" wrote in message ... I have a workbook names "Space.xls" and when a certain macro is run it goes and pulls date from a workbook named "Moon.txt". This all works fine. However, I need a code that will look to see if "Moon.txt" is open and if it is not to skip that part of the code. -- Thanks Shawn |
If Then to check if a workbook is open
That isn't exactly what I need. When the macro is running it gets to a line
that says: Windows("Moon.txt").Activate I need a If Then statement something like: If Window("Moon.txt") Open Then Window("Moon.txt").Activate etc. etc. etc. End If -- Thanks Shawn "Don Guillett" wrote: This code will open if closed or activate if open. Works from a workbook name typed in a cell. Sub GetWorkbook() If ActiveCell.Value = "" Then Exit Sub workbookname = ActiveCell.Value On Error GoTo OpenWorkbook Windows(workbookname & ".xls").Activate Exit Sub OpenWorkbook: Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen End Sub -- Don Guillett SalesAid Software "Shawn" wrote in message ... I have a workbook names "Space.xls" and when a certain macro is run it goes and pulls date from a workbook named "Moon.txt". This all works fine. However, I need a code that will look to see if "Moon.txt" is open and if it is not to skip that part of the code. -- Thanks Shawn |
If Then to check if a workbook is open
I don't want it to open it if it is closed. ????
-- Thanks Shawn "Don Guillett" wrote: Did you try deleting the first line and changing the 2nd line workbookname = ActiveCell.Value workbookname = "moon" and changing .xls to .txt -- Don Guillett SalesAid Software "Shawn" wrote in message ... That isn't exactly what I need. When the macro is running it gets to a line that says: Windows("Moon.txt").Activate I need a If Then statement something like: If Window("Moon.txt") Open Then Window("Moon.txt").Activate etc. etc. etc. End If -- Thanks Shawn "Don Guillett" wrote: This code will open if closed or activate if open. Works from a workbook name typed in a cell. Sub GetWorkbook() If ActiveCell.Value = "" Then Exit Sub workbookname = ActiveCell.Value On Error GoTo OpenWorkbook Windows(workbookname & ".xls").Activate Exit Sub OpenWorkbook: Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen End Sub -- Don Guillett SalesAid Software "Shawn" wrote in message ... I have a workbook names "Space.xls" and when a certain macro is run it goes and pulls date from a workbook named "Moon.txt". This all works fine. However, I need a code that will look to see if "Moon.txt" is open and if it is not to skip that part of the code. -- Thanks Shawn |
If Then to check if a workbook is open
On Error Resume Next
Set oWB = Workbooks("Moon.txt") On Error Goto 0 If Not oWB Is Nothing Then 'do the stuff End If -- HTH Bob Phillips (replace xxxx in the email address with gmail if mailing direct) "Shawn" wrote in message ... I have a workbook names "Space.xls" and when a certain macro is run it goes and pulls date from a workbook named "Moon.txt". This all works fine. However, I need a code that will look to see if "Moon.txt" is open and if it is not to skip that part of the code. -- Thanks Shawn |
All times are GMT +1. The time now is 12:08 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com