Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Mar 2018
    Location
    Australia
    Posts
    48
    Thanks
    20
    Thanked 0 Times in 0 Posts

    Error message folder is encrypted, but not encrypted

    Below is a Python code, it is suppose to Run a VBA macro, but there seems to be a error on the Win 7 side.
    Code:
    import win32com.client
    xl=win32com.client.Dispatch("Excel.Application")
    xl.Workbooks.Open(Filename="C:\MYFOLDERNAME",ReadOnly=0)
    xl.Application.Run("py_counter_test")
    xl.Workbooks(1).Close(SaveChanges=1)
    xl.Application.Quit()
    xl=0
    This the error message I get in the script editor for Python is:


    com_error-2147352567,'Exception occured',(0,"Microsoft \excel', Excel cannot access 'MYFOLDERNAME,, The document may be read-only or encrypted,", 'xlmain11.chm.,0,-2146827284),none)
    I know I have not encrypted the folder, it is simply a "New Folder" in C:\ and re-named.
    It is a test folder in C:\ to test the code


    Name of Folder in Drive C:
    C:\MYFOLDERNAME
    ;
    Name of workbook is:
    PY-COUNTER.xls
    ;
    Name of VBA macro is:
    py_counter_test
    ;


    Excel version: 2010
    OS: Win 7 pro
    Latest Python version: 3.7
    PyScripter (latest version)

    Thanks

    I do use .bat scripts to Run .py scripts. The .bat script is run by VBA.
    VBA-bat-py works, but not the other way round it seems

  2. #2
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,962
    Thanks
    63
    Thanked 1,124 Times in 1,045 Posts
    Have you left the name of the workbook out?
    Code:
    xl.Workbooks.Open(Filename="C:\MYFOLDERNAME\PY-COUNTER.xls",ReadOnly=0
    cheers, Paul

  3. The Following User Says Thank You to Paul T For This Useful Post:

    XP_7 (2018-08-02)

  4. #3
    Lounger
    Join Date
    Mar 2018
    Location
    Australia
    Posts
    48
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Have you left the name of the workbook out?
    yes.
    Amended code
    Code:
    #py_counter_test
    import win32com.client
    xl=win32com.client.Dispatch("Excel.Application")
    xl.Workbooks.Open(Filename="C:\MYFOLDERNAME\PY-COUNTER.xlsm",ReadOnly=0)
    xl.Application.Run("py_counter_test")
    xl.Workbooks(1).Close(SaveChanges=1)
    xl.Application.Quit()
    xl=0
    Left out: PY-COUNTER.xlsm

    The VBA code for testing is simply,

    Code:
    Sub py_counter_test()
        Range("C5").Select
        Range("C7").Value = Range("C7").Value + 1
        ActiveWorkbook.Save
    End Sub
    It brings up al sort of other error messages, but the counter increases, then I know the macro was Run.

    will try to figure out the errors.

    Thanks Paul

  5. #4
    Lounger
    Join Date
    Mar 2018
    Location
    Australia
    Posts
    48
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Code:
    #py_counter_test
    import win32com.client
    xl=win32com.client.Dispatch("Excel.Application")
    xl.Workbooks.Open(Filename="C:\MYFOLDERNAME\PY-COUNTER.xlsm",ReadOnly=0)
    xl.Application.Run("py_counter_test")
    
    #xl.Workbooks(1).Close(SaveChanges=1)
    #xl.Application.Quit()
    #xl=0

    I've hashed # out the parts of the code so it does not close the workbook.
    And, for those who are very new to Python, it simpler to test and Run scripts using IDLE editor, comes standard with Python download.

    OK, so what is the bigger picture in all this ?

    When VBA stops working on html web queries, I hope by then a Python set of scripts can get for me what Excel VBA won't off the web page I use and place that same info back into Excel, or txt. I can still pick up the data from txt file or csv.

    Even then it's a stab in the dark, cos I still don't know if the info will be the same.

Posting Permissions

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