Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default How to check for Open File!

I am trying to check if a workbook is open and if it is select a tab. If the
workbook is not open, I was to open it. Any ideas?

For Each wbk In Application.ActiveWindow
If wbk.Name = "FC CONSTRUCTION TRACKER_V2.xls" Then
Sheets("FC Construction").Select
End If
Next wbk
Workbooks.Open ("S:\_TRACKERS\NJ Daily Totals\CM Update Trackers\FC
CONSTRUCTION TRACKER_V2.xls")
Windows("FC CONSTRUCTION TRACKER_V2.xls").Activate
Sheets("FC Construction").Select
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default How to check for Open File!

dim myPath as string
dim myFileName as string
dim wkbk as workbook
dim wks as worksheet

'include the trailing backslash!
myPath = "S:\_TRACKERS\NJ Daily Totals\CM Update Trackers\"
myfilename = "FC CONSTRUCTION TRACKER_V2.xls"

set wkbk = nothing
on error resume next
set wkbk = workbooks(myfilename)
on error goto 0

if wkbk is nothing then
'open it!
set wkbk = workbooks.open(filename:=mypath & myfilename)
else
'do nothing, it's already open
end if

set wks = nothing
on error resume next
set wks = wkbk.worksheets("FC Construction")
on error goto 0

if wks is nothing then
msgbox "FC Construction wasn't found!
else
application.goto wks.range("A1"),scroll:=true
end if


Ayo wrote:

I am trying to check if a workbook is open and if it is select a tab. If the
workbook is not open, I was to open it. Any ideas?

For Each wbk In Application.ActiveWindow
If wbk.Name = "FC CONSTRUCTION TRACKER_V2.xls" Then
Sheets("FC Construction").Select
End If
Next wbk
Workbooks.Open ("S:\_TRACKERS\NJ Daily Totals\CM Update Trackers\FC
CONSTRUCTION TRACKER_V2.xls")
Windows("FC CONSTRUCTION TRACKER_V2.xls").Activate
Sheets("FC Construction").Select


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default How to check for Open File!

You do not need to check if it is open. Hyperlink to it. If it is already
opened you will jump to it, otherwise it will be opened:

Sub anothre()
Dim s As String
s = "S:\_TRACKERS\NJ Daily Totals\CM Update Trackers\FCCONSTRUCTION
TRACKER_V2.xls"
ActiveWorkbook.FollowHyperlink Address:=s
Sheets("FC Construction").Select
End Sub

--
Gary''s Student - gsnu200799
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
check if file is already open mohavv Excel Discussion (Misc queries) 1 October 15th 07 12:08 AM
If Then to check if a workbook is open Shawn Excel Discussion (Misc queries) 5 November 25th 06 04:29 PM
excel 2003 saved file will not open without a blank workbook open Bob Excel Discussion (Misc queries) 4 November 11th 06 04:24 PM
In Excel - Use Windows Explorer instead of File Open to open file KymY Excel Discussion (Misc queries) 1 August 5th 06 09:59 PM
Check if workbook open dkipping Excel Discussion (Misc queries) 4 May 24th 06 02:00 PM


All times are GMT +1. The time now is 09:03 AM.

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

About Us

"It's about Microsoft Excel"