Using GetObject

G

Graham944

I need to inspect a custom document property but can't open the document
because of name conflicts with already open files.

What I am doing is set up a link to the file with GetObject and then use
this to access the custom property. It works fine for the first time but
seems to leave a reference to the file after the macro has closed. This then
causes problems elsewhere in the macro when it is re-run.

Ideas please.

Graham.
 
J

Jan De Messemaeker

Hi,

I never use getobject but I suspect that you have to put the object you get
to nothing after its use.
HTH
 
G

Graham944

Jan,

I have tried setting the object to nothing but it makes no difference.

I always use GetObject simply because I don't know anything better. If you
can suggest an alternative I would be very grateful. As I pointed out
originally, I can't simply open the file because of name conflict with files
that are already open.

Thanks,
Graham.
 
J

Jan De Messemaeker

Hi,

When not in Project, I always use (it may just be a personl preference...)

dim prapp as msproject.application
set prapp= createobject("msproject.application")
Then when I want to open a file
prapp.fileopen "full address of the file"

in the end
prapp.fileclose

and ultimately
prapp.quit
set prapp=nothing

That does not leave any trace.
Mind you for the excel application it sometimes does leave a trace, but for
Project it is clean.

HTH
 
G

Graham944

Jan,

I've tried this but I'm afraid that it still doesn't solve the problem
because a file can't be opened twice, so it won't be possible to read the
CustomDocumentProperties of a file in a folder if the file is already open
(and possibly updated). However, in thinking about the problem I have come
to the conclusion that the simplest way is to detect the situation before
trying to read the parameters and simply ask the user to close the file
before proceeding.

Thanks for your help with this. It's nice to know that there isn't some
magic solution that I was missing.

Graham.
 
J

Jan De Messemaeker

Hello,

Oh boy, I misunderstood your question from the beginning!
In the application approach, you can loop through the open projects (the
Projects collection) and when the full name corresponds, assign it to the
project variable instead of opening it!

Sorry I didn't see that from the start.
 
G

Graham944

Jan,

Thanks for the help.

Graham.

Jan De Messemaeker said:
Hello,

Oh boy, I misunderstood your question from the beginning!
In the application approach, you can loop through the open projects (the
Projects collection) and when the full name corresponds, assign it to the
project variable instead of opening it!

Sorry I didn't see that from the start.

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
http://users.online.be/prom-ade/
+32-495-300 620
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top