Handling Open Files

W

WD

The sample code below creates a master project from inserted projects.

i = 1
sFileInUse = False
InUse = 1
Do Until i = cnt
MyAttr = GetAttr(prjdir & sFileArray(i)) And vbReadOnly
If MyAttr <> 0 Then
sFileInUse = True
InUse = InUse + 1
sFilesInUse(InUse) = sFileArray(i)
GoTo Continue
Else
ConsolidateProjects Filenames:=prjdir & sFileArray(i),
NewWindow:=False, AttachToSources:=False, _
HideSubtasks:=True, openpool:=pjDoNotOpenPool
End If
Continue:
sFileInUse = False
i = i + 1
Loop

Using GetAttr, I am trying to determine if the file is in use. However, I am
not getting the correct result. How else can I determine if a file is
currently opened before I insert it into the master project? Any tips would
be helpful.

WD
 
J

Jan De Messemaeker

Hi,

IMHO, GetAttr gives a lot of information but not whether the file is in use
or not.
From the top of my head, I would say first check whether or not it is opened
in this machine by running through

For each anyproject in projects
if anyproject.fullname="the comparison name" then...
next anyproject

If not I'd open it and check whether the newly opened (hence the active)
project is readonly.

HTH
 
W

WD

Jan --

Are you saying that you would open it before inserting it and then close it
and insert it if it isn't read-only? What's the overhead on that cycle? I
have 19 projects that I need to do this to with a potential increase in the
number of projects.

I don't have a concern about the file being opened on the local computer as
the files that I will be using are owned by other PMs. I am basically
looking to build a static master project for reporting purposes.
 
J

Jan De Messemaeker

Hi,

Haha!
Then just use consolidateprojects method, regardless of whether they are
open or not.
Only problem is, you see the copy on disk (saved last time) not what anybody
is working on.
HTH
 
W

WD

Jan --

I am using the consolidateprojects method, however, if someone is using the
file that I wish to insert I still get a fileinuse message do I want to
save...I can't insert it read-only because I am not attaching to the source
(if I was using read-only then I would get around the message)...I'll keep
checking around...the only other way that I can think of getting around the
message is by sending an <enter> key stroke followed by a <cancel> key
stroke....similar to a quiet install

I am not sure how to do either one...

WD
 
J

Jan De Messemaeker

Hi,

Do you mean you do not know how to enter strokes?
Look for the help on the Sendkeys method
(When in VBA I open a file I always use a Sendkeys "~")

HTH
 

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