none
VBA macro works fine in Office 2010, but not in Office 2007 RRS feed

  • Question

  • I don't think I have used any code that is Office 2010 specific, some examples of things that don't seem to work properly any more are

    '  I tried lots of permutations dumming down this one
                        Set objPresentation = objPPApp.Presentations.Open((DefaultTemplateLocation & DefaultTemplateName), False, True, True)
    '  Even a simple Dim
    Dim oSALayout As Office.SmartArtLayout

    Doesn't seem to be saving the default shapes anymore...

    I have checked the Tools --> References and for the items that show as missing, Like Powerpoint object library 14.0 or  Excel Library 14.0,  I have gone and selected the PowerPoint Object Library 12.0 etc.(that seems to be the latest one available in the list). 

    Is there a way I can get the Object 14.0 object library's and use them in Office 2007 if that is the problem?

    The Macro is a MS Project VBA code and the client wanted it to work in Project/Office 2007 but I developed in 2010 because that is what I had.

    Most of the posts I have found seem to be pointed at people have problems with upgrading to new version, doesn't seem like many people have to deal with this downgrading issue.

    Open to suggestions... outside of the obvious force client to upgrade :)

    I just found the VBA forum and I think I should probably move this thread there, but I don't know how.  From what I have seen there, forwards/backwards compatibility is not great.


    Rick Auburn, ME and Newport, RI


    Friday, February 15, 2013 2:35 PM

Answers

  • Hi Ocean_Engineer,

    Thank you for posting in the MSDN Forum.

    Sub justopen()
    Dim objPPApp As Object
    Dim objPresentation As Object
    Set objPPApp = New PowerPoint.Application
    objPPApp.Visible = msoTrue
    Set objPresentation = objPPApp.Presentations.Open("C:\ITC_Template.pptx")
    End Sub

    I've tried this code on my Office 2007 machine and it works fine.

    Try to repair installation and make sure you've installed all updates.

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, February 27, 2013 12:46 PM
    Moderator

All replies

  • Hi Rick

    I can move the question for you, but I'm not sure the VBA forum is going to be any better...

    FWIW, going backwards is never guaranteed and rarely works well. The rule is to develop against the oldest Office version if you have any hopes at all of code working across versions. It's quite possible that something which works in 2010 won't in 2007.

    However, in your particular case I believe that the immediate issue is your Library references. They usually won't work backwards, either. You would need to open your VBA on system where 2007 is installed and change these References to version 12.0, not 14.0.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, February 15, 2013 5:14 PM
    Moderator
  • Thank you for the candid answer Cindy.

    I have my references set to Version 12.0, but still a basic Open doesn't work... I can't say I was expecting this at all.  I have done all my coding in VBA.  I see a lot of developers out there are using VSTO, I was avoiding because I thought it would limit me for version compatibility.  Now I see that I am going to be limited anyway.  Would it make sense to move my code to VSTO.  Would it be a different language?  Would it help me try to get my code to work with Office 2007?  Or will I likely be stuck in the same way.  I am assuming there isn't a good translation guide out there to help with my problem.

    Thanks again,

    Rick


    Rick Auburn, ME and Newport, RI

    Friday, February 15, 2013 6:43 PM
  • Hi Rick

    You'd be stuck the same way - the same restrictions apply going from a newer to an older version. Unless...

    You use VS 2010 (or 2012) and leverage the "embed interop types" that were introduced with the .NET Framework 4.0. That lets you put the necessary interfaces for working with the Office application right into your code, and this is version-independent. But it won't let you use something from a newer version in an older version if it's not present in the older version.

    A similar thing is possible in VBA using late-binding: declare everything as an Object and remove all references to the Office application libraries.

    However, if you've set ALL the Office references to 12, then I'd expect your code to work. What error message are you getting? With Presentations.Open the only required parameter is the first one, the file name. Have you tried using only that?


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, February 16, 2013 7:55 AM
    Moderator
  • Hi Cindy, 

       I didn't think that I was using things from Office 2010 that wouldn't have been available in 2007, but clearly I was mistaken there. I certainly didn't expect a problem with Presentations.Open... I did verify that I have the same checkmarks in Tools--> References in both versions.  Including Excel, Powerpoint, Office, Project all version 12.0 in Office 2007 and 14.0 in Office 2010.

    I dummed down the file open as a test and just tried running this snippet of code.

    Sub justopen()
    Dim objPPApp As Object
    Dim objPresentation As Object
    Set objPPApp = New PowerPoint.Application
    objPPApp.Visible = msoTrue
    Set objPresentation = objPPApp.Presentations.Open("C:\ITC_Template.pptx")
    End Sub

    And still got the runtime error :

    Method 'Open' of Object 'Presentations' failed.

    I have heard of "late binding" and wasn't really sure of what that had meant. 

    I will look into the "embed interop types" for the future if I am going to have to constantly stay behind the curve with this client.

    Thanks for the help.

      


    Rick Auburn, ME and Newport, RI

    Monday, February 18, 2013 2:36 PM
  • Hi Rick

    I'd expect it to work; no idea why you'd get this error message. Since you're using VBA at this point, try asking the question here:

    http://answers.microsoft.com/en-us/office/forum/powerpoint?tm=1361203527938

    This is where all the PowerPoint specialists hang out and someone there might have experience with your problem.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, February 18, 2013 4:05 PM
    Moderator
  • I am hesitant to post in a Powerpoint sepcific forum because the justopen sub just ran... if I run from a macro within Powerpoint VBA.  It just doesn't run from a VBA macro residing in a MS Project file.  Even though the same libraries selected in both places.

    I will think about it some more and maybe post there.


    Rick Auburn, ME and Newport, RI


    Monday, February 18, 2013 5:16 PM
  • Hi Ocean_Engineer,

    Thank you for posting in the MSDN Forum.

    Sub justopen()
    Dim objPPApp As Object
    Dim objPresentation As Object
    Set objPPApp = New PowerPoint.Application
    objPPApp.Visible = msoTrue
    Set objPresentation = objPPApp.Presentations.Open("C:\ITC_Template.pptx")
    End Sub

    I've tried this code on my Office 2007 machine and it works fine.

    Try to repair installation and make sure you've installed all updates.

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, February 27, 2013 12:46 PM
    Moderator