Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 370
  • Last Modified:

Recently used files for Office apps

Greetings,

I need to be able to read the list of most recently opened files in MS office apps (Word, excel etc).

Any ideas/code are welcome - where the list may be located, how to read it, OS compatibility issues etc. Any suggestions for other common business apps are also welcome

Thanks
Vlad
0
vladh
Asked:
vladh
  • 3
  • 3
  • 2
  • +4
1 Solution
 
JaymolCommented:
Try this....

Create a new unit (not a project - just the unit), and copy and paste this code into it.....

//////////  CODE STARTS HERE   /////////////////

unit WinDir;

interface

uses
  Windows, Registry;

Type
      TWinDirectory=(wdAppData, wdCache, wdCookies, wdDesktop, wdFavourites, wdFonts, wdHistory,
                                             wdNetHood, wdPersonal, wdPrintHood, wdPrograms, wdRecent, wdSendTo,
                 wdStartMenu, wdStartUp, wdTemplates, wdUser);

function       GetWindowsDir(wdDirectoryName : TWinDirectory): String;

implementation

function      ReadRegString(rHKey: HKey; rKey, rName: String): String;
var
      WinReg      :      TRegistry;
begin
      WinReg:=TRegistry.Create;
  WinReg.RootKey:=rHKey;
  WinReg.OpenKey(rKey, False);
  Result:=WinReg.ReadString(rName);
  WinReg.Free;
end;

function       GetWindowsDir(wdDirectoryName : TWinDirectory): String;
begin
      Case wdDirectoryName of
        wdAppData            : Result:=ReadRegString(HKEY_CURRENT_USER,
                                                                                                                'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                                'AppData');
        wdCache                  : Result:=ReadRegString(HKEY_CURRENT_USER,
                                                                                                                'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                                'Cache');
        wdCookies            : Result:=ReadRegString(HKEY_CURRENT_USER,
                                                                                                                'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                                'Cookies');
        wdDesktop            : Result:=ReadRegString(HKEY_CURRENT_USER,
                                                                                                                'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                                'Desktop');
        wdFavourites: Result:=ReadRegString(HKEY_CURRENT_USER,
                                                                                                                'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                                'Favorites');
        wdFonts                  : Result:=ReadRegString(HKEY_CURRENT_USER,
                                                                                                                'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                                'Fonts');
        wdHistory            : Result:=ReadRegString(HKEY_CURRENT_USER,
                                                                                                                'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                                'History');
        wdNetHood            : Result:=ReadRegString(HKEY_CURRENT_USER,
                                                                                                                'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                                'NetHood');
        wdPersonal      : Result:=ReadRegString(HKEY_CURRENT_USER,
                                                                                                                'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                                'Personal');
        wdPrintHood      : Result:=ReadRegString(HKEY_CURRENT_USER,
                                                                                                                'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                                'PrintHood');
        wdPrograms      : Result:=ReadRegString(HKEY_CURRENT_USER,
                                                                                                                'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                                'Programs');
        wdRecent            : Result:=ReadRegString(HKEY_CURRENT_USER,
                                                                                                                'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                                'Recent');
        wdSendTo            : Result:=ReadRegString(HKEY_CURRENT_USER,
                                                                                                                'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                                'SendTo');
        wdStartMenu      : Result:=ReadRegString(HKEY_CURRENT_USER,
                                                                                                                'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                                'Start Menu');
        wdStartUp            : Result:=ReadRegString(HKEY_CURRENT_USER,
                                                                                                                'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                                'StartUp');
        wdTemplates      : Result:=ReadRegString(HKEY_CURRENT_USER,
                                                                                                                'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                                'Templates');
  end;
end;

end.

///////////  CODE ENDS HERE   //////////////////


Save the unit in your Delph's Bin directory as WinDir and then create a new application.

Stick a button on it and double click it.

Put this code in the OnClick event of the button...

     ShowMessage(GetWindowsDir(wdRecent));

Run it and click the button.

Hope this helps.

John.
0
 
JaymolCommented:
I forgot to say....when you create the new application with the button on the form, you need to put WinDir in the uses clause.

John.
0
 
sorinvCommented:
For Excel 97 here's where you can read from the registry the list:

HKEY_CURRENT_USER\Software\Microsoft\Office\8.0\Excel\Recent File List

Word 97: HKEY_CURRENT_USER\Software\Microsoft\Office\8.0\Word\Data

however, this is a binary format and I'm not sure how you can convert it.

For Office 2000 just replace 8.0 with 9.0

Sorin
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
EpsylonCommented:
This works for Office 97 and higher:



uses ComObj;

procedure TForm1.Button1Click(Sender: TObject);
var
  Word, Excel: Variant;
  i: Integer;
begin
  try
    Word := GetActiveOleObject('Word.Application');
  except
    Word := CreateOleObject('Word.Application');
  end;
  for i := 1 to Word.RecentFiles.Count do
    ListBox1.Items.Add(Word.RecentFiles.Item(i).Path + '\' + Word.RecentFiles.Item(i).Name);
//  Word.Quit;
  Word := Unassigned;

  try
    Excel := GetActiveOleObject('Excel.Application');
  except
    Excel := CreateOleObject('Excel.Application');
  end;
  for i := 1 to Excel.RecentFiles.Count do
    ListBox1.Items.Add(Excel.RecentFiles.Item[i].Path);
//  Excel.Quit;
  Excel := Unassigned;
end;


For opening/closing Office apps see

http://www.djpate.freeserve.co.uk/AutoWord.htm#CloseWord
0
 
vladhAuthor Commented:
Sorin,

Thanks, I am looking for a solution that addresses all my concerns at the same time

Thanks
0
 
vladhAuthor Commented:
Epsylon,

Your code works well but I also forgot to mention one small but important requirement: no office (or any other) apps are going to be opened at the time my code runs (startup) and none can be started. My app is designed to run on background gathering certain config ststistics and users must not even be aware that it is running. So opening and closing Word or Excel for the purpose of getting the list of recently opened files is out of the question.

I need another way of doing it, a direct registry read is certainly an option and I knew about Excel MRU file location record in the registry (as Sorin suggested). I need similar for Word and other apps.

Thanks
Vlad
P.S.:Thanks for the link... Quite useful to answer questions I haven't even had the chance to ask yet :)

0
 
EpsylonCommented:
It will be a hard job to cover all offive versions and all platforms...
0
 
vladhAuthor Commented:
Epsylon,

did you mean 'More points'? :))

I am looking for all possible suggestions and coding is not a problem.  One of the ideas is to read a binary registry value containing Word's MRU files; if you have a piece of code that can help read binary values and put them in Tstrings, this will help. In w2K, the same value is in MULTI_STRING format, how do I read it?


Regards,
Vladimir
0
 
EpsylonCommented:
No, I don't have the means to test all platforms and I only have office 2000 at my disposal.
0
 
MoondancerCommented:
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if they are still open in 14 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20082202.html
http://www.experts-exchange.com/questions/Q.20086538.html
http://www.experts-exchange.com/questions/Q.11330458.html
http://www.experts-exchange.com/questions/Q.20150370.html
http://www.experts-exchange.com/questions/Q.20173317.html
http://www.experts-exchange.com/questions/Q.20270564.html
http://www.experts-exchange.com/questions/Q.20287717.html



*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @14 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 
Russell LibbySoftware Engineer, Advisory Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

To be PAQ/Refund

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Thank you,
Russell

EE Cleanup Volunteer
0
 
PashaModCommented:
paq and no refund

PashaMod
CS Moderator @Experts Exchange
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now