Lucas Soler said:
How do I:
1. validate that an Excel file is open
2. Get hold of the file so I can write to it?
Thanks.
Lucas,
Here is the snippet of code I use:
Set Xl = GetObject(, "Excel.application")
If Err <> 0 Then
On Error GoTo 0
Set Xl = CreateObject("Excel.Application")
If Err <> 0 Then
MsgBox "Excel application is not available on this
workstation" _
& Chr(13) & "Install Excel or check network connection",
vbCritical
FilterApply Name:="all tasks"
ViewApply Name:=oldview
Set Xl = Nothing
On Error GoTo 0 'clear error function
Exit Sub
End If
End If
Xl.Workbooks.Add
BookNam = Xl.Workbooks(Xl.Workbooks.Count).Name
You can also see this type of code in context by visiting fellow MVP,
Jack Dahlgren's website at:
http://masamiki.com/project/macros.htm
Take a look at his macro, "Export hierarchy to Excel"
Hope this helps.
John
Project MVP