none
Recent Presentations/recent files not updated when 'Saveas' method is used RRS feed

  • Question

  • Hi,

    I am developing some add-ins for MS-Office 2010 using VB in VS 2010.  I have a small utility that creates a new version of the currently open presentation with the current date/time appended to the file name and archives the old version.

    All the code is working fine except that the newly saved file is not being shown in the recent files list (which I understand is stored in the registry).

    I am using a "thisPresentation.SaveAs(newFileName)" method, then closing that file so that I can move the old one (which Powerpoint still has locked until I close) then re-opening the new file.

    Any ideas much appreciated.

    Have searched all forums etc.

    Dave



    Wednesday, July 6, 2011 4:27 AM

Answers

  • Hi Dave,

     

    Thanks for posting in the MSDN Forum.

     

    According to your description, I write a snippet to handle your issue. Please try it and see whether it is you want:

     

    Imports Microsoft.Office.Tools.Ribbon
    Imports PowerPoint = Microsoft.Office.Interop.PowerPoint
    Imports Microsoft.Win32
    
    Public Class Ribbon1
    
    Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load
    
    End Sub
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles Button1.Click
      Dim PPApplication As PowerPoint.Application = Globals.ThisAddIn.Application
      Dim ppPresentation As PowerPoint.Presentation
      Dim originalFileName As String
      Dim dateString As String
      Dim key As RegistryKey
      Dim ItemCount As Integer
      Dim MaxCount As Integer
    
      ppPresentation = PPApplication.ActivePresentation()
      originalFileName = ppPresentation.FullName.Replace(".pptx", "")
      dateString = Date.Now.ToString("yyyyMMdd-hhmmss")
      ppPresentation.SaveAs(originalFileName + dateString + ".pptx")
      key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Office\\14.0\\PowerPoint\\File MRU", RegistryKeyPermissionCheck.ReadWriteSubTree)
    
      If key Is Nothing Then
        MsgBox("Failed to Open MRU")
      Else
        ItemCount = key.ValueCount
        MaxCount = key.GetValue("Max Display")
        If ItemCount < MaxCount Then
          For i As Integer = 0 To ItemCount - 2
          Dim temp As String = key.GetValue("Item " + CStr(ItemCount - 1 - i))
          key.SetValue("Item " + CStr(ItemCount - i), temp)
        Next
          key.SetValue("Item 1", "[F00000000][T01CC3C0000000000][O00000000]*" + originalFileName + dateString + ".pptx")
        ElseIf ItemCount = MaxCount + 1 Then
          For i As Integer = 0 To MaxCount - 2
            Dim temp As String = key.GetValue("Item " + CStr(MaxCount - 1 - i))
            key.SetValue("Item " + CStr(MaxCount - i), temp)
          Next
          key.SetValue("Item 1", "[F00000000][T01CC3C0000000000][O00000000]*" + originalFileName + dateString + ".pptx")
        End If
        key.Close()
      End If
    End Sub
    End Class
    
    

     

    I suggest you backup your registry before you test due to some security conside.

    How to back up the registry 
    Before you edit the registry, you’d better export the keys in the registry that you plan to edit, or back up the whole registry.
    If a problem occurs, you can then follow the steps in the How to restore the registry section of this article to restore the registry to its previous state.

     

     

    I hope it can help you.

     

    Have a good day,

     

    Tom

     


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

     

     


    Thursday, July 7, 2011 8:56 AM
    Moderator
  • Hi Dave,

    <<Interestingly I did find that the Word object model does support a 'Recentfiles' collection of 'RecentFile' objects so it was really surprising that I couldn't find the same structure under Powerpoint?>>

    I think the different produce group of the Office will do different investigations to find out the goal for different software. So there exist different designations of them. The investigations provided important information for every product groups to improve the product’s feature. And you are able to find the more content of Word PIA library than PowerPoint due to Word is used more frequently and feedback are more than PowerPoint.

    Collect the feedbacks and submit them to Microsoft is a sort of import job for us to do every day, what you side will be considered as a potential top issue. When many community members show similar issue in the forum we will submit it. And perhaps the new interface, class, method or property will be added in to the library to support that issue.

    <<Also, do you happen to know what the significance is of "Max Display"? ValueCount is self explanatory however you have written the code to run the loop in two different ways depending on the relative value of Max Display and ValueCount - I couldn't quite understand why we couldn't just use ValueCount and a single loop, ignoring the Max Display value?>>

    When I designed this snippet, I consider the situation for someone may not use PowerPoint frequently. So the many only less count of recent file items in the MRU. We will cause exception and break out from the process if we use the index which beyond the range of the collection. I designed two loops to iterate the items to fit the different situation for this issue. Naturally it hasn’t been optimized. You can optimize the snippet by yourself.

    << As a final question, in the registry, the value prefix ("[F00000000][T01CC3C0000000000][O00000000]*") changes for each of the entries in the second group of characters (the prefix stays the same) - in your code you just plug all '0' there - is this significant?>>

    I can’t understand the mean of the string ahead of the file path too. So I try to generate the string that you mentioned in the question by my experience. This string has no problem to handle your issue but I can’t ensure that is the only answer for your issue. I think this string will store the information of the date, interval time of the particular file is used, the count of the file is used etc. However I don’t know the algorithm of it, I have no reference about it. You are able to try different string to handle your case. The string will be correct when you open the file from the recent file list.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 12, 2011 3:09 AM
    Moderator

All replies

  • Hi Dave,

     

    Thanks for posting in the MSDN Forum.

     

    According to your description, I write a snippet to handle your issue. Please try it and see whether it is you want:

     

    Imports Microsoft.Office.Tools.Ribbon
    Imports PowerPoint = Microsoft.Office.Interop.PowerPoint
    Imports Microsoft.Win32
    
    Public Class Ribbon1
    
    Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load
    
    End Sub
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles Button1.Click
      Dim PPApplication As PowerPoint.Application = Globals.ThisAddIn.Application
      Dim ppPresentation As PowerPoint.Presentation
      Dim originalFileName As String
      Dim dateString As String
      Dim key As RegistryKey
      Dim ItemCount As Integer
      Dim MaxCount As Integer
    
      ppPresentation = PPApplication.ActivePresentation()
      originalFileName = ppPresentation.FullName.Replace(".pptx", "")
      dateString = Date.Now.ToString("yyyyMMdd-hhmmss")
      ppPresentation.SaveAs(originalFileName + dateString + ".pptx")
      key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Office\\14.0\\PowerPoint\\File MRU", RegistryKeyPermissionCheck.ReadWriteSubTree)
    
      If key Is Nothing Then
        MsgBox("Failed to Open MRU")
      Else
        ItemCount = key.ValueCount
        MaxCount = key.GetValue("Max Display")
        If ItemCount < MaxCount Then
          For i As Integer = 0 To ItemCount - 2
          Dim temp As String = key.GetValue("Item " + CStr(ItemCount - 1 - i))
          key.SetValue("Item " + CStr(ItemCount - i), temp)
        Next
          key.SetValue("Item 1", "[F00000000][T01CC3C0000000000][O00000000]*" + originalFileName + dateString + ".pptx")
        ElseIf ItemCount = MaxCount + 1 Then
          For i As Integer = 0 To MaxCount - 2
            Dim temp As String = key.GetValue("Item " + CStr(MaxCount - 1 - i))
            key.SetValue("Item " + CStr(MaxCount - i), temp)
          Next
          key.SetValue("Item 1", "[F00000000][T01CC3C0000000000][O00000000]*" + originalFileName + dateString + ".pptx")
        End If
        key.Close()
      End If
    End Sub
    End Class
    
    

     

    I suggest you backup your registry before you test due to some security conside.

    How to back up the registry 
    Before you edit the registry, you’d better export the keys in the registry that you plan to edit, or back up the whole registry.
    If a problem occurs, you can then follow the steps in the How to restore the registry section of this article to restore the registry to its previous state.

     

     

    I hope it can help you.

     

    Have a good day,

     

    Tom

     


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

     

     


    Thursday, July 7, 2011 8:56 AM
    Moderator
  • Tom,

    Many thanks for this (I did post this reply earlier but it seems to have gone missing). I am working through applying this code to my project - it all makes good sense however I have a couple of follow on questions that you (or someone else) may be able to help with (largely because I can't find documentation on the Registry):

    • Interestingly I did find that the Word object model does support a 'Recentfiles' collection of 'RecentFile' objects so it was really surprising that I couldn't find the same structure under Powerpoint?
    • Also, do you happen to know what the significance is of "Max Display"? ValueCount is self explanatory however you have written the code to run the loop in two different ways depending on the relative value of Max Display and ValueCount - I couldn't quite understand why we couldn't just use ValueCount and a single loop, ignoring the Max Display value?
    • As a final question, in the registry, the value prefix ("[F00000000][T01CC3C0000000000][O00000000]*") changes for each of the entries in the second group of characters (the prefix stays the same) - in your code you just plug all '0' there - is this significant?

    Once again, many thanks - Dave

    Tuesday, July 12, 2011 12:37 AM
  • Hi Dave,

    <<Interestingly I did find that the Word object model does support a 'Recentfiles' collection of 'RecentFile' objects so it was really surprising that I couldn't find the same structure under Powerpoint?>>

    I think the different produce group of the Office will do different investigations to find out the goal for different software. So there exist different designations of them. The investigations provided important information for every product groups to improve the product’s feature. And you are able to find the more content of Word PIA library than PowerPoint due to Word is used more frequently and feedback are more than PowerPoint.

    Collect the feedbacks and submit them to Microsoft is a sort of import job for us to do every day, what you side will be considered as a potential top issue. When many community members show similar issue in the forum we will submit it. And perhaps the new interface, class, method or property will be added in to the library to support that issue.

    <<Also, do you happen to know what the significance is of "Max Display"? ValueCount is self explanatory however you have written the code to run the loop in two different ways depending on the relative value of Max Display and ValueCount - I couldn't quite understand why we couldn't just use ValueCount and a single loop, ignoring the Max Display value?>>

    When I designed this snippet, I consider the situation for someone may not use PowerPoint frequently. So the many only less count of recent file items in the MRU. We will cause exception and break out from the process if we use the index which beyond the range of the collection. I designed two loops to iterate the items to fit the different situation for this issue. Naturally it hasn’t been optimized. You can optimize the snippet by yourself.

    << As a final question, in the registry, the value prefix ("[F00000000][T01CC3C0000000000][O00000000]*") changes for each of the entries in the second group of characters (the prefix stays the same) - in your code you just plug all '0' there - is this significant?>>

    I can’t understand the mean of the string ahead of the file path too. So I try to generate the string that you mentioned in the question by my experience. This string has no problem to handle your issue but I can’t ensure that is the only answer for your issue. I think this string will store the information of the date, interval time of the particular file is used, the count of the file is used etc. However I don’t know the algorithm of it, I have no reference about it. You are able to try different string to handle your case. The string will be correct when you open the file from the recent file list.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 12, 2011 3:09 AM
    Moderator
  • Tom,

    Once again many thanks for your speedy reply - I think you have completely covered my questions.

    I also understand that features in the PIA will be implemented on a demand basis so the questions about recent files being accessible through a property of the powerpoint application object was more an observation than anything else.

    I did find it very easy to manipulate the registry commands once I had your base code and now have the code working to remove missing files as well as add the file I am working with.  I guess my only comment is that there is a chance of mucking up the registry so it would be nice to have an optional parameter in the Save and SaveAs methods to add or not add the saved file to the File MRU.

     

    Many thanks

    Dave

     

    Tuesday, July 12, 2011 7:25 AM