Solved

Recently used files for Office apps

Posted on 2001-07-13
12
347 Views
Last Modified: 2010-05-18
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
Comment
Question by:vladh
  • 3
  • 3
  • 2
  • +4
12 Comments
 
LVL 6

Expert Comment

by:Jaymol
ID: 6280438
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
 
LVL 6

Expert Comment

by:Jaymol
ID: 6280443
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
 

Expert Comment

by:sorinv
ID: 6280466
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
 
LVL 13

Expert Comment

by:Epsylon
ID: 6280597
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
 
LVL 3

Author Comment

by:vladh
ID: 6281634
Sorin,

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

Thanks
0
 
LVL 3

Author Comment

by:vladh
ID: 6286855
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Expert Comment

by:Epsylon
ID: 6286867
It will be a hard job to cover all offive versions and all platforms...
0
 
LVL 3

Author Comment

by:vladh
ID: 6287075
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
 
LVL 13

Expert Comment

by:Epsylon
ID: 6287106
No, I don't have the means to test all platforms and I only have office 2000 at my disposal.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6975896
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
 
LVL 26

Expert Comment

by:Russell Libby
ID: 8703028
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
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 8818656
paq and no refund

PashaMod
CS Moderator @Experts Exchange
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Copy file in dll not working but working on exe ! 18 88
Delphi application Soap connection 5 96
creating threads in delphi 1 84
DBGrid or StringGrid ? 6 71
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now