I have code that seems to work??? It opens an Excel Spread Sheet if it exists or does nothing if it does not exist (I will add a msg box if it does not). It also works if the Excel app is already open. However, it does not work if more than one Excel app is open.
Q: How do I check to see if it is open
Q: How do I set focus to an open book
Q: Am I asking the right questions?
Can someone help please?
Dim MyPath
MyPath = "\\dbtest" ' Set the path.
' The Directory begins with the PM.Value
MyPath = MyPath + "\" + Trim(PM.Value) + "\"
Dim MyName As String
MyName = Dir(MyPath) ' Retrieve the first entry.
Dim MyFile As String
Dim Xl As Excel.Application
Dim XlBook As Excel.Workbook
Dim XlSheet As Excel.Worksheet
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
If MyName = [Job_No].Value Then
'Define and open Excel Template
Set Xl = CreateObject("Excel.Application")
Set XlBook = GetObject(MyPath + MyName)
Xl.Visible = True
XlBook.Windows(1).Visible = True
Set XlSheet = XlBook.Worksheets(1)
XlBook.Sheets("C.O. log").Select
End If
End If
MyName = Dir ' Get next entry.
Loop
Set Xl = Nothing
Set XlBook = Nothing
Set XlSheet = Nothing
Q: How do I check to see if it is open
Q: How do I set focus to an open book
Q: Am I asking the right questions?
Can someone help please?
Dim MyPath
MyPath = "\\dbtest" ' Set the path.
' The Directory begins with the PM.Value
MyPath = MyPath + "\" + Trim(PM.Value) + "\"
Dim MyName As String
MyName = Dir(MyPath) ' Retrieve the first entry.
Dim MyFile As String
Dim Xl As Excel.Application
Dim XlBook As Excel.Workbook
Dim XlSheet As Excel.Worksheet
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
If MyName = [Job_No].Value Then
'Define and open Excel Template
Set Xl = CreateObject("Excel.Application")
Set XlBook = GetObject(MyPath + MyName)
Xl.Visible = True
XlBook.Windows(1).Visible = True
Set XlSheet = XlBook.Worksheets(1)
XlBook.Sheets("C.O. log").Select
End If
End If
MyName = Dir ' Get next entry.
Loop
Set Xl = Nothing
Set XlBook = Nothing
Set XlSheet = Nothing