![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Mar 2002
Location: Paul
Posts: 34
|
Hi all,
Does anybody know the syntax for an IF STATEMENT to check if an Excel workbook is already open? I have a form that opens 5 workbooks before performing various tasks. I want to avoid the message "xyz is already open. Re-opening will cause any changes you made to be discarded. Do you want to reopen xyz?". Any Thoughts? Many Thanks. Cheers - Paul |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Mar 2002
Posts: 363
|
Try this:
Sub OpenFile() wb = "C:My Documentsxyz.xls" For Each wbk In Workbooks If wbk.FullName = wb Then Windows(wbk.Name).Visible = True wbk.Activate GoTo endsub End If Next wbk Workbooks.Open Filename:=wb endsub: End Sub This will unhide and activate the file if it's open or open it if it's not.
__________________
It's never too late to learn something new. Ricky |
|
|
|
|
|
#3 |
|
New Member
Join Date: Mar 2002
Location: Paul
Posts: 34
|
Many Thanks Ricky!
PROBLEM SOLVED Cheers - Paul |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|