How to check for Open File!

  • Thread starter Thread starter Ayo
  • Start date Start date
A

Ayo

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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top