locked
Excel.Application.Workbooks.Open error RRS feed

  • Question

  • Hi,

    I have written a simple Powershell Script to open a Excel Book, run a macro and exit.

    We run it on a Windows 10 Enterprise with Excel 2010.

    On one machine it works without error and another machine it gives the following error: Unable to get the Open property of the Workbooks class

    Function RefreshExcel { 
    Param ( $xls )
    
    $Books = $Excel.Workbooks
    Try {
       $workbook = $Books.Open($xls)
    } catch {
        Write $Error[0].ToString()
        Return $false
    }
    Start-Sleep -s 30
    Try {
       $Excel.Application.Run("MettreAJours")
    } catch {
        Write $Error[0].ToString()
        Return $false
    }
    Try {
       $workbook.save()
    } catch {Return $false}
    $workbook.close()
    }
    
    $Excel = New-Object -ComObject excel.application
    $Excel.Visible = $true
    RefreshExcel("http://sharepoint.server/equipe/si/ProjectBurnDown.xlsm")
    $Excel.quit()

    On both machine I can open the file manually in Excel.

    I have try to repair the Office installation as suggested somewhere else on the forum, but it didn't help.

    Thanks for helping me.

    H_V_L

    Wednesday, January 24, 2018 10:31 PM

All replies

  • Hi H_V_L,

    Please try to check that both Excel have same version of updates installed.

    If they are different then try to install the same update as other machine on which this code is working.

    Then try to check whether it runs correctly or not.

    Also try to check that user have enough rights to access that file from other machine.

    I also find in some old thread that by creating the folders on location below may solve the issue.

    For 64 bit make this folder.
    C:\Windows\SysWOW64\config\systemprofile\Desktop

    For 32 bit make this folder.
    C:\Windows\System32\config\systemprofile\Desktop

    Let us know whether it solves your issue or not.

    If issue persist then we will try to provide further suggestions to solve the issue.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 25, 2018 2:12 AM
  • Hi Deepak,

    Hi H_V_L,

    Please try to check that both Excel have same version of updates installed.

    If they are different then try to install the same update as other machine on which this code is working.

    Both version use Excel version 14.0.7188.5002(32bits)

    Then try to check whether it runs correctly or not.

    Also try to check that user have enough rights to access that file from other machine.

    On both machine, I can open the file manually

    I also find in some old thread that by creating the folders on location below may solve the issue.

    For 64 bit make this folder.
    C:\Windows\SysWOW64\config\systemprofile\Desktop

    For 32 bit make this folder.
    C:\Windows\System32\config\systemprofile\Desktop

    Let us know whether it solves your issue or not.

    Unfortunately, creating the folder didn't solve the problem.

    If issue persist then we will try to provide further suggestions to solve the issue.

    Thank you,

    H_V_L

    Thursday, January 25, 2018 5:46 PM
  • Hi H_V_L,

    Can you inform us, Are you using 32 bit or 64 bit os? and for which you had created a folder?

    Also try to check whether you had installed any Windows related updates recently or not.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 26, 2018 8:38 AM
  • Hi Deepak

    Hi H_V_L,

    Can you inform us, Are you using 32 bit or 64 bit os? and for which you had created a folder?<\p>

    The OS is 64 bits, we have tried to create both folders

    Also try to check whether you had installed any Windows related updates recently or not.<\p>

    Both machines are updated to the same Windows update.

    Thanks,

    Friday, January 26, 2018 7:06 PM
  • Hi H_V_L,

    Are you able to open any other Excel file using this code on that problematic machine?

    So we can decide whether the issue related with particular file or it can be reproduce with any Excel file.

    It will help us to narrow down the issue.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 29, 2018 9:28 AM
  • Hi Deepak,

    Are you able to open any other Excel file using this code on that problematic machine?

    So we can decide whether the issue related with particular file or it can be reproduce with any Excel file.

    It will help us to narrow down the issue.

    The behavior is the same with any Excel file on this machine.

    Regards, H_V_L
    Monday, January 29, 2018 6:28 PM
  • Hi H_V_L,

    I find that if file is left open by manually or using code and you try to access it using the code then you can get same kind of error.

    Because file is not available for further processing.

    I suggest you to check and verify that file is close and also not used by any other user at same time.

    Then try to run the code and check whether it solve the issue or not.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 30, 2018 8:27 AM
  • Hi Deepak,

    I find that if file is left open by manually or using code and you try to access it using the code then you can get same kind of error.

    Because file is not available for further processing.

    I suggest you to check and verify that file is close and also not used by any other user at same time.

    Then try to run the code and check whether it solve the issue or not.

    Regards

    Deepak

    I made sure that the file was closed, before I run the script.

    I have found that if I try to run a similar script on a file without macros (.xlsx)

    When calling the open, the script will generate the following exception.

    Exception de HRESULT : 0x800A03EC

    Regards,

    H_V_L

    Tuesday, January 30, 2018 2:05 PM
  • Hi H_V_L,

    I will try to find more possible causes that can cause this issue and let you informed you about that.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 5, 2018 9:22 AM
  • Hi H_V_L,

    I will try to find more possible causes that can cause this issue and let you informed you about that.

    Regards

    Deepak.

    Hi Deepak,

    We have decided to format and reinstall the machine and it works, therefore something was corrupted on the machine. Fortunately the machine was not used for other task, but if the machine was used for other task this solution would not be acceptable. We would be interested to know possible causes so we can try if this happen again.

    Regards,

    H_V_L

    Monday, February 12, 2018 4:57 PM
  • Hi H_V_L,

    Not sure, If it is corruption or any other reason behind this issue.

    But if reinstalling the OS solve the issue then now you can create a restore point for your OS.

    So if in future, You meet with the same issue then you can simply restore your OS and things will again start work.

    Reference:

    How to refresh, reset, or restore your PC

    As your issue is solved now, I suggest you to mark your own last post as an answer.

    It will help us to close this thread, It will also helpful to other community members who will meet with same kind of issue in future.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 13, 2018 1:20 AM