Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-20-2014, 08:10 AM
dherr dherr is offline Is there a solution to change the recentfilelist programmatically Windows 8 Is there a solution to change the recentfilelist programmatically Office 2007
Advanced Beginner
Is there a solution to change the recentfilelist programmatically
 
Join Date: Nov 2014
Location: Austria
Posts: 45
dherr is on a distinguished road
Default Is there a solution to change the recentfilelist programmatically

Hi all,
sometimes the name of the drive changes where my excelfiles are stored at. In this case all the items of the recentfiles in the list can't be used further on.
So I thought to write a macro to change the drive name of this files, but without success.
Does someone know how to solve this problem?

regards
Dietrich
Reply With Quote
  #2  
Old 11-20-2014, 12:52 PM
charlesdh charlesdh is offline Is there a solution to change the recentfilelist programmatically Windows 7 32bit Is there a solution to change the recentfilelist programmatically Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

Hi,

Try tis bit of code in the "Thisworksheet" module.
When the user close the workbook it should be save to the specified drive.
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    
     Application.DisplayAlerts = False
    ActiveWorkbook.Save Filename:="C:\Users\laura\Documents\Excel\ExcelFiles\David.xlsm"
    Application.DisplayAlerts = True
    ActiveWorkbook.Close
End Sub
Reply With Quote
  #3  
Old 11-20-2014, 10:43 PM
macropod's Avatar
macropod macropod is offline Is there a solution to change the recentfilelist programmatically Windows 7 64bit Is there a solution to change the recentfilelist programmatically Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

All you can do through the GUI in such situations is to delete the files from the recent files list. That list is maintained in the Windows Registry and, while it's possible to edit the Registry entries programmatically, you could do serious damage to your OS if you get it wrong.

charlesdh: I can't see how your macro is at all relevant to the OP's problem, since it: (a) pre-supposes the file has been opened; and (b) that you know you want to save it to the hard-coded folder. Adding such code to every workbook, especially with hard-coded paths that may be invalidated (e.g. what do you suppose will happen if the path isn't found or the user wants to save the file to a USB drive?) is likely to create a greater problem than it will save. Furthermore, you can't specify a filename with the Save method, so your code wouldn't work anyway.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 11-21-2014, 09:39 AM
dherr dherr is offline Is there a solution to change the recentfilelist programmatically Windows 8 Is there a solution to change the recentfilelist programmatically Office 2007
Advanced Beginner
Is there a solution to change the recentfilelist programmatically
 
Join Date: Nov 2014
Location: Austria
Posts: 45
dherr is on a distinguished road
Default

Hi Paul,
thanks for your answer.
You are right, the thread of 'charlesdh' is not to the problem...

But I was afraid, that there is no direct way to do this.
The next idea is:
How is the menu called which shows if you use the right mousebutton on a recentfiles name?
Eventually you could add an item to this menu where you could ask if the drive is actual yet.
(Excuse my English, I'm from Austria...)
Regards
Dietrich
Reply With Quote
  #5  
Old 11-21-2014, 02:52 PM
macropod's Avatar
macropod macropod is offline Is there a solution to change the recentfilelist programmatically Windows 7 64bit Is there a solution to change the recentfilelist programmatically Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The right-click pop-up is a built-in Office function. You cannot modify it to give the ability to add a new item or change an existing item's name or path.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 11-21-2014, 04:42 PM
dherr dherr is offline Is there a solution to change the recentfilelist programmatically Windows 8 Is there a solution to change the recentfilelist programmatically Office 2007
Advanced Beginner
Is there a solution to change the recentfilelist programmatically
 
Join Date: Nov 2014
Location: Austria
Posts: 45
dherr is on a distinguished road
Default

PITY!!!
Greetings and have a nice weekend!
Dietrich
Reply With Quote
  #7  
Old 11-22-2014, 03:13 AM
dherr dherr is offline Is there a solution to change the recentfilelist programmatically Windows 8 Is there a solution to change the recentfilelist programmatically Office 2007
Advanced Beginner
Is there a solution to change the recentfilelist programmatically
 
Join Date: Nov 2014
Location: Austria
Posts: 45
dherr is on a distinguished road
Default

Hi Paul,
next idea:
can I use a click event on this recentfilelist to code somewhat?
greetings-
Dietrich
Reply With Quote
  #8  
Old 11-22-2014, 06:20 AM
macropod's Avatar
macropod macropod is offline Is there a solution to change the recentfilelist programmatically Windows 7 64bit Is there a solution to change the recentfilelist programmatically Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

In the unlikely event that it is possible, it would require some serious Windows API programming.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 11-22-2014, 07:46 PM
whatsup whatsup is offline Is there a solution to change the recentfilelist programmatically Windows 7 64bit Is there a solution to change the recentfilelist programmatically Office 2010 32bit
Competent Performer
 
Join Date: May 2014
Posts: 137
whatsup will become famous soon enough
Default

Hi @all
I understand you guys are talking of the recentfiles of office, not the one the OS provides.In this case you got the chance to temper with the list's items using the application-object recentfiles. It provides three methods:
.Open ---> to check if the file opens (if not an error occurs, and you can handle this one)
.Delete ---> to delete the item from the list
.Add ---> to add a new item, in this case the same item with the new path
The following example assumes that the second item in recentfiles doesn't open, due to a wrong Drive's name. The Drive of the path will be changed, and is added to the list:
Code:
Sub ChangeRecentFiles()
Dim strPath As String, strName As String
Dim strNewDrive As String
Dim strNewPath As String, strNewName As String
Dim lngFile As Long
 
strNewDrive = "H:"
lngFile = 2
 
strName = Application.RecentFiles.Item(lngFile).Name
strPath = Application.RecentFiles.Item(lngFile).Path
strNewPath = strNewDrive & Right(strPath, Len(strPath) - 2)
 
On Error GoTo DeleteListItem
Application.RecentFiles.Item(lngFile).Open
 
Exit Sub
DeleteListItem:
    Application.RecentFiles.Item(lngFile).Delete
    Application.RecentFiles.Add Name:=strNewPath
    strNewName = Application.RecentFiles.Item(1).Path
End Sub
Cheers
Reply With Quote
  #10  
Old 11-22-2014, 08:36 PM
macropod's Avatar
macropod macropod is offline Is there a solution to change the recentfilelist programmatically Windows 7 64bit Is there a solution to change the recentfilelist programmatically Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi whatsup,

That might give the OP something to work with. It'd probably need some inputboxes, etc. to solicit the missing file's entry name and/or index # and where to look for the replacement, but at least it's heading in the right direction.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 11-23-2014, 01:48 AM
dherr dherr is offline Is there a solution to change the recentfilelist programmatically Windows 8 Is there a solution to change the recentfilelist programmatically Office 2007
Advanced Beginner
Is there a solution to change the recentfilelist programmatically
 
Join Date: Nov 2014
Location: Austria
Posts: 45
dherr is on a distinguished road
Default

Hi all,
it's great that you are thinking about my problem!! Thank you.
The code of 'whatsup' ... I will try it in a macro shortly...
Greetings from Salzburg and a nice Sunday-
Dietrich
Reply With Quote
  #12  
Old 11-23-2014, 03:21 AM
gmayor's Avatar
gmayor gmayor is offline Is there a solution to change the recentfilelist programmatically Windows 7 64bit Is there a solution to change the recentfilelist programmatically Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Maybe http://www.gmayor.com/custom_recent_files_lists.htm would help?
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #13  
Old 11-23-2014, 05:54 AM
dherr dherr is offline Is there a solution to change the recentfilelist programmatically Windows 8 Is there a solution to change the recentfilelist programmatically Office 2007
Advanced Beginner
Is there a solution to change the recentfilelist programmatically
 
Join Date: Nov 2014
Location: Austria
Posts: 45
dherr is on a distinguished road
Default

Oh, thank you for sending us this link, Graham!!
It looks great what you have programmed. I will try it shortly and inform you about the outcome.
Best regards.
Dietrich
Reply With Quote
  #14  
Old 12-02-2014, 08:31 AM
dherr dherr is offline Is there a solution to change the recentfilelist programmatically Windows 8 Is there a solution to change the recentfilelist programmatically Office 2007
Advanced Beginner
Is there a solution to change the recentfilelist programmatically
 
Join Date: Nov 2014
Location: Austria
Posts: 45
dherr is on a distinguished road
Default Little Solution...

Hi all,
I have a little bit programmed in VBA and created a UserForm with some code.
Unfortunately this solution you can use in Excel2007 only. When I tried it in Word2007 an unintelligible fact appeared. In Word and Excel we have the same RecentFileList to work with, but in Word-VBA you don't have all properties for this object at hand. What did Microsoft think in that case? I really don't know... In Powerpoint you have the same RecentFilesList too, but there is no programming to this object possible.
All you can say to this facts is
I have attached the UserForm file and you can import it into Excel. The code has some comments in German and I tried to translate them...
The solution is working fine by me. You have to mark the new drive where your files now are 'positioned'. Then mark these same files where you want to change the 'old' drive name into the 'new' drivename. Then push 'ausführen'-Button. At the end you have a new RecentFilesList which works with the new items.

Greetings-
Dietrich
Attached Files
File Type: zip RecentFilesChanging.zip (1.5 KB, 8 views)
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a solution to change the recentfilelist programmatically Creating Event Handlers Programmatically pluviosilla Word VBA 4 11-06-2014 05:36 PM
Is there a solution to change the recentfilelist programmatically Adding macro to normal.dotm programmatically etippelt Word VBA 6 04-08-2013 05:55 PM
Programmatically convert Office documents to PDF from C# hemaneelagiri Office 0 10-21-2011 06:07 AM
outlook programmatically read an attachment into byte array chriskaza81 Outlook 0 11-19-2010 01:03 AM
Programmatically changing folder item selection Richard Cook Outlook 0 02-09-2007 02:25 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:26 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft