Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 271
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 271
Default 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




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,726
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel exits unexpectedly or hangs the second time I open workbook r_m_i Excel Discussion (Misc queries) 0 February 9th 06 10:14 PM
Blank workbook opens when try to open any existing book poloboyUK Excel Discussion (Misc queries) 2 February 2nd 06 08:35 PM
Workbook fails to open - Excel 2003 nc Excel Discussion (Misc queries) 1 February 2nd 06 06:33 PM
Links only update when external workbook is open CMB Excel Worksheet Functions 6 November 8th 05 12:39 AM
Importing Data from unopened Workbook into an open Workbook GrayesGhost Excel Discussion (Misc queries) 0 March 5th 05 11:25 PM


All times are GMT +1. The time now is 04:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"