CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2017
    Posts
    13

    Question Can't automate Excel from Windows 10 (MFC program)

    I'm using Visual C++ Professional Version 2015 update 3. I have a program that automates Excel and works fine in our Windows 7 computers. However, on Windows 10, Excel doesn't even launch (CreateDispatch() returns 0).

    There is a problem with a Windows Function, CLSIDFromProgID(L"Excel.Application", &clsid), which returns error 0x800401fe, which has the explanation: “Application was launched but it didn't register a class factory”. This is a curious explanation because all the function does is pick up the CLSID from the registry (it doesn’t launch Excel). And “Excel.Application” is in the registry for the Windows 10 computer just like for our Windows 7 computers. I was thinking that maybe Windows 10 doesn’t allow automation to work from clients that are from an “unknown publisher”, but then it should work with UAC off. (And when I ran it with UAC set to "never notify", the warning message did not appear when starting PI_Dats. Maybe it’s not really disabled, it just doesn’t issue the warning?)

    On the Local Disk Properties Security tab, Administrators have full control and I set Users also to full control. Any ideas as to how to automate Excel from Windows 10 would be greatly appreciated.

    Thanks,
    Gary

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Can't automate Excel from Windows 10 (MFC program)

    Is the same version of excel installed on the windows 10 machine? Are they both 32bit machines? 64bit? Or different between both machines?

  3. #3
    Join Date
    Jan 2017
    Posts
    13

    Re: Can't automate Excel from Windows 10 (MFC program)

    Quote Originally Posted by Arjay View Post
    Is the same version of excel installed on the windows 10 machine? Are they both 32bit machines? 64bit? Or different between both machines?
    Thank you for your questions. Both machines are 64 bit. I'm using Excel 2013 on the Windows 7 machine, Excel 2016 on Windows 10. We've been using the same Windows functions to control Excel for decades, I suppose a new version might no longer support it... But wouldn't there be an announcement somewhere?

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Can't automate Excel from Windows 10 (MFC program)

    Try Excel 2013 on a clean install of Win 10. Also try Excel 2016 on Win 7.

    Lastly, are the Excel versions 32 or 64 bit?

  5. #5
    Join Date
    Jan 2017
    Posts
    13

    Re: Can't automate Excel from Windows 10 (MFC program)

    Quote Originally Posted by Arjay View Post
    Try Excel 2013 on a clean install of Win 10. Also try Excel 2016 on Win 7.

    Lastly, are the Excel versions 32 or 64 bit?
    Thank you for your query. Both versions of Excel are 32 bit. I shall commence experimenting although I'm doing a different experiment first because it is easy to do. I'll be trying a 32 bit program to automate 32 bit Excel on 64 bit Windows 10. I shall return with results.

    Thanks again..

  6. #6
    Join Date
    Jan 2017
    Posts
    13

    Re: Can't automate Excel from Windows 10 (MFC program)

    Maybe it's noteworthy that I cannot find Excel.exe on my windows 10 computer using Windows Explorer. I can launch it easily enough by clicking on the Start button, going to E, and there it is. But if I use Explorer, go to C:\Program Files and search for excel.exe, no files are found. (Same for C\Program Files (x86)). On my windows 7 computer excel.exe is found at C:\Program Files\Microsoft Office 15\root\office15

    On my Windows 10 computer, there is no "Microsoft Office x" directory, whether x is blank or a number in C:\Program Files or c:\Program Files (x86).

    If I run regedit on my Windows 7 computer and search for excel.exe, I can find a value with the file path. If I run regedit on my Windows 10 and search for excel.exe, I find values with the name "PackageRelativeExecutable" and the data is "Office16\excel.exe." However, if I do a search using Windows Explorer on the C: drive for "office16", there are no results.

    Perhaps the fact that I cannot find Excel.exe on my windows 10 computer is related to the problem of automation not finding it? How can I help automation find Excel?

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Can't automate Excel from Windows 10 (MFC program)

    When you automate an office app like excel, you are accessing it through its COM interface. For this to work, excel must be registered as a COM server.

    To get an idea of what I'm talking about, go to the registry of the Win 7 machine where the auomation works and search for "excel.exe" and "Excel.Application". I suspect you will find many more registry entries.

    This leads me to believe that Excel isn't installed properly on the Win 10 machine. Are you sure the Excel 2016 full version is installed, not the 365 version? Can you try to install Excel 2013 on Win 10?

  8. #8
    Join Date
    Jan 2017
    Posts
    13

    Resolved Re: Can't automate Excel from Windows 10 (MFC program)

    You are right. I reinstalled Office and now there's an Excel.exe file in C:\program files (x86)\Microsoft Office\root\Office16. I'm amazed that Excel seemed to run just fine without it! Anyway, now the automation function both connect with and launch Excel. Thanks very much for your responses.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured