Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#6
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
excel exits unexpectedly or hangs the second time I open workbook | Excel Discussion (Misc queries) | |||
Blank workbook opens when try to open any existing book | Excel Discussion (Misc queries) | |||
Workbook fails to open - Excel 2003 | Excel Discussion (Misc queries) | |||
Links only update when external workbook is open | Excel Worksheet Functions | |||
Importing Data from unopened Workbook into an open Workbook | Excel Discussion (Misc queries) |