Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where's that thread?

Status
Not open for further replies.

monagan

Technical User
May 28, 2004
138
US
Hi all,

I recently saw a thread on what to do when a workbook is already open.

I believe it was something like, code opened a workbook, and they need the code to not open if the workbook was already opened.

I cannot find that thread, I know it was on this site.
I figured a lot of the experts on here participated in it and might remember it
 
its just
sub open
Workbooks.Open FileName:="c:\Documents\Resources.xls"
End Sub

if the workbook is already open it does not matter...i think
 
There's an error message that comes up saying that that file is already open, do you want to reopen it and lose any changes
 
oh yeah of course sorry my fault
this code will not open the workbook if it exists

Sub Open()
Dim wkbk As Workbook
Dim WorkbookName As String
WorkbookName = "Glossary Finance & MET terms.xls"
On Error Resume Next
Set wkbk = Workbooks(WorkbookName)
On Error GoTo 0
If wkbk Is Nothing Then
Workbooks.Open FileName:="C:\your paht here.xls"
End If
End Sub
 
sorry for mods...if the workbook is open it will not open it again...

Sub Open()
Dim wkbk As Workbook
Dim WorkbookName As String
WorkbookName = "names of file here.xls"
On Error Resume Next
Set wkbk = Workbooks(WorkbookName)
On Error GoTo 0
If wkbk Is Nothing Then
Workbooks.Open FileName:="C:\your paht here.xls"
End If
End Sub

if yu need more guidance tell me
 
Sub IsOpen()

Dim wkbk As Workbook
Dim WorkbookName As String
WorkbookName = "TIME SHEET.xls"
On Error Resume Next
Set wkbk = Workbooks(WorkbookName)
On Error GoTo 0
If wkbk Is Nothing Then
Workbooks.Open filename:="C:\Documents and Settings\AMY C\Desktop\TIME SHEETS.xls"
End If

wkbk = Nothing when Time Sheets.xls is open
 
Set wkbk = Workbooks(WorkbookName)

'Set wkbk = workbooks(<subscript out of range>)
 
substitute the name of YOUR workbook for "WorkbookName"

Rgds, Geoff

Never test the depth of water with both feet

Help us to help you by reading FAQ222-2244 before you ask a question
 
Sorry Geoff, I wrote my error wrong.

When I hover over WorkbookName I get my workbook name

When I hover over workbooks I get

Workbooks(WorkbookName)=<subscript out of range>


 
I'm sorry, I figured it out.

I'm so embarrassed.

I just forgot the "s" on the end of the name
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top