View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default If Then to check if a workbook is open

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