|
-
Jul 25th, 2006, 08:41 AM
#1
Thread Starter
Lively Member
Microsoft Office Late Binding
OK, guys I use what I think is a very good way of setting up the automation process with office.... here go's - dont be too harsh if you dont like it.
VB Code:
Public oApp as Object
Public Function ExcelOpen() As Boolean
ExcelOpen = False
Set oApp = Nothing
On Error Resume Next
Set oApp = GetObject(, "Excel.application")
If Err.Number > 0 Then
Set oApp = CreateObject("Excel.Application")
Err.Clear
End If
ExcelOpen = Not (oApp Is Nothing)
If Not ExcelOpen Then
MsgBox "Are you sure Microsoft Excel is installed on your computer?"
End If
End Function
This can be used to open up any office application, just copy and change the "Excel" bit.
I am not suffering from insanity......... ...........I am loving every minute of it.
-
Jul 25th, 2006, 09:29 AM
#2
Re: Microsoft Office Late Binding
That looks good, but there is room for improvement:
The thing I noticed first is that you dont have any "close" process, so the object variables will not get cleared (so waste memory) and/or the application (Excel) will not close properly (which you may not notice until you shut down the PC). Of course you may have a seperate function to do this, but just haven't shown it to us!
The other issue is your error handling (or rather, ignoring), which isn't quite right. It is understandable that you are using Resume Next for the GetObject part, however you should return to "normal service" as soon as possible afterwards - using a proper error handler to deal with any issues that arise, and give apropriate error messages to the user.
It also seems to me that it may be better to check (at the start of the function) if the application object (oApp) already refers to an instance of the application, and if so simply activate that one rather than creating another.
-
Jul 26th, 2006, 05:53 AM
#3
Thread Starter
Lively Member
Re: Microsoft Office Late Binding
I did say "don't be harsh"...
LOL, no thats great, I accept your valid points. I do have another function to Close up everything... will probably append the above post when I get chance.
The program this was written for is a document managing utility where lots of documents are opoened up one after the other... rather than closing the object all the time, it was much faster to leave it open - if that makes any sense...
anyways, will take your points on board... many thanks
I am not suffering from insanity......... ...........I am loving every minute of it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|