Hi Denise,
You should really have posted this in an NG like microsoft.public.excel.programming, but here's some code you could use. It includes
a variety of error checks before trying to open the file:
Option Explicit
Dim wbFullName As String
Function IsLocked(wbFullName As String) As Boolean
On Error Resume Next
Open wbFullName For Binary Access Read Write Lock Read Write As #1
Close #1
IsFileOpen = Err.Number
Err.Clear
End Function
Sub OpenWorkbook()
Dim wbName As String
Dim wbPath As String
wbPath = "c:\data\"
wbName = "test.xls"
wbFullName = wbPath & wbName
If Dir(wbFullName) = "" Then
MsgBox "Cannot find: " & wbFullName
ElseIf Not Workbooks(wbName) Is Nothing Then
MsgBox "The file: " & wbFullName & " is already open!"
ElseIf IsLocked(wbFullName) Then
MsgBox "The file: " & wbFullName & " is in use by another user!"
Else
Workbooks.Open wbFullName
End If
End Sub
Simply change the path & filename to suit your needs.
--
Cheers
macropod
[MVP - Microsoft Word]
Denise Payne said:
I am using Excel.
What I am trying to do is use a Command Button to link to a macro that will
open a speadsheet from another file(Spreadsheet 1), then update another
spreadsheet(Spreadsheet 2) from the first spreadsheet. Then, close
everything. It is modeling data and there are 4323 rows and 50 columns. I am
trying to create a command on one spreadsheet that will update the data at
the touch of a button.