Link to home
Start Free TrialLog in
Avatar of mhonzell
mhonzellFlag for United States of America

asked on

Can VBA be used to identify filename in-use by another application?

I'm using Access 2007 to import an .XML file into Excel, modifing the format, then saving the file as input to a table in Access. Currently, this has to be done due to .XML attributes do not automatically import into Access tables. (ie. <Employee  ID="John"> : ID="John" is not imported into Access.) I will attempt this after I solve the question below.

The file being imported is generated by the user in a non-Microsoft program and saved using standard windows FileDialog. The file may not have been opened by this program, but instead created through it's use. The file must be saved in a specific location prior to use by Access.

Can VBA be use to identify the filename in use, Opened or Saved, by this executable with the user's input through FileDialog?

The method I currently have only identifies the filename if opened (not saved) via Windows Explorer.
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

<<I'm using Access 2007 to import an .XML file into Excel, modifing the format, then saving the file as input to a table in Access. Currently, this has to be done due to .XML attributes do not automatically import into Access tables. (ie. <Employee  ID="John"> : ID="John" is not imported into Access.) I will attempt this after I solve the question below.>>

  There are other methods of importing, such as using the xml document object or opening the file directly and parsing it.

<<Can VBA be use to identify the filename in use, Opened or Saved, by this executable with the user's input through FileDialog?>>

  You can use the Dir() command to check for the existance of a file, but I'm not sure that's what you want.

<<The method I currently have only identifies the filename if opened (not saved) via Windows Explorer. >>

  Not sure what you mean by this...

JimD.
Avatar of mhonzell

ASKER

Unfortunately, no.
The file generated, or opened is only known to the user, so I cannot search for the file's existence until I know the name.
In regards to your second comment:
If I open a file (not executable) by double-clicking, or a command-line, the process can be echoed. But, in my case, the file will always be opened or saved via the FileDialog window.
SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I was really hoping that was not the case.

Kind of defeats a one button solution for the user.
Now, I'll have to have them search for the file they created and select it. This will work, but seems inelegant after the user has already performed this process to either open or save the file.

Hmm... Maybe I can get the vendor of my utility (it's a specialized program) to limit the filename to a fixed size and include it as a passable parameter to Access. Then, if the file cannot be found (changed, or hasn't saved the file yet) then a search by the user or error message would be warranted. They haven't been too willing to do much in this area.

Thanks!

  Maybe if you explained the process that the user goes through and how your app interacts with that as that is still not clear to me, I might be able to offer something else.

JimD.

 
User opens an application that allows interface to several databases and via a graphical interface develops a flow chart that relates items in these databases.

When the file is saved via FileDialog, the flow chart is converted to .XML information and saved at a location saved by the user.

At this time, or a later time, the user with this file open, assigns a unique ID to the file and then selects an option to "certify" the flow chart. This process is conducted in another database by comparing the child node values with entries in the database and setting flags,

The application "passes" only one unique piece of information: the ID assigned to the file and contained in the file. But, to get this I need the filename since the vendor did not make the "Certify" button actually pass any information. (It can only open the database.)

Another answer to this is to allow the user to start the database, search for the file to certify and then complete the process without re-opening the prior application. (This is a fairly straightforward answer.) But, I was trying to make this more of a single step that could be completed before exiting the first application making it appear to be part of the same program.

Did this provide enough detail?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Unfortunately, how the database is called appears to be little more than a shortcut that must be pre-configured prior to running the application. This aspect is still in development and I'm trying to get it more configurable, but the vendor does not want any responsibility for the external database/app.

I agree #2 is too messy since this network functions with Win2000 - Win7 and Unix. (Even though the file in question will always be opened or saved in Windows <something>.

I guess I don't see how Dir() is going to help if I don't know the filename.
Example: The file was created two weeks ago, but opened today for "certification." Several files have been created in the two week period since the file in question was created.

One direction I have considered:
  1) Bring the window to focus
  2) Quietly force a save of the file via the menu bar commands.
            This isn't so quiet if the file has not been previously saved and must close the certification window first.
  3) Then search for the most recent file in the specific directory.

It just seemed to me that if the app already knows the filename to complete the Save function, it must be accessible.

Thanks again.
I'm close to throwing in the towel.

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
After showing the vendor this entire "conversation", the vendor has included the unique ID to the command-line. Problem solved.
Thank you, JDettman
Dir() will not solve the entire problem, but provided a technique the vendor was willing to work with by providing one additional piece of information when the external application is called.

1) An internal search of files will have to occur to find the file with the passed unique ID.
2) Non-existence will require a prompt to save the file first.