Home > Mobile >  Run excel macro (locked) using python
Run excel macro (locked) using python

Time:01-02

It isn't duplicate. Macro models are locked. Can't execute programmatically

So we have an excel where we fill some data. Click on the given button. It performs some calculations (using macros probably) and then fill the result in the excel only. We want to take another step forward and want to automate the task to fill the input data too.

The problem is modules are locked i can't programmatically execute macro. enter image description here

Tried executing with python. enter image description here

If we open that file with libre office (linux) it shows this. enter image description here

The excel file is the freely available Fatigue index calculator If its not possible to do it this way. Is there any other way? Can i somehow use the button present in the excel? Any help is appreciated.

I am not an excel guy, correct me if I am wrong somewhere. Can provide more info.

CodePudding user response:

If the Workbook itself is locked you can remove the password from the workbook. The steps to do so is listed here.

If that doesn't work try, copying the macro and running it using VBSript

Lastly, as a last resort, you can try using PyAutoGui to automate the process of entering the password in the password field.

CodePudding user response:

Pasted from a previous post from his blog:

For Excel 2007/2010 (.xlsm) files do following steps:

  1. Create a new .xlsm file.

  2. In the VBA part, set a simple password (for instance 'macro').

  3. Save the file and exit.

  4. Change file extention to '.zip', open it by any archiver program.

  5. Find the file: 'vbaProject.bin' (in 'xl' folder).

  6. Extract it from archive.

  7. Open the file you just extracted with a hex editor.Find and copy the value from parameter DPB (value in quotation mark), example: 8.DPB="282A84CBA1CBA1345FCCB154E20721DE77F7D2378D0EAC90427A22021A46E9CE6F17188A". (This value generated for 'macro' password. You can use this DPB value to skip steps 1-8)

  8. Do steps 4-7 for file with unknown password (file you want to unlock).

  9. Change DBP value in this file on value that you have copied in step

  10. If copied value is shorter than in encrypted file you should populate missing characters with 0 (zero). If value is longer - that is not a problem (paste it as is).

  11. Save the 'vbaProject.bin' file and exit from hex editor.

  12. Replace existing 'vbaProject.bin' file with modified one.

  13. Change extention from '.zip' back to '.xlsm' Now, open the excel file you need to see the VBA code in.

 The password for the VBA code will simply be macro (as in the
example I'm showing here).
  • Related