Wrong behavior of the automation security in Excel

Discussion in 'Mac Programming' started by Vreditel, Sep 7, 2011.

  1. Vreditel macrumors newbie

    Joined:
    Jul 28, 2011
    #1
    Hello all!!!
    I need to when excel file which contains macros is open, Excel don't show "Enable/Disable Macros" dialog. I write next code, but it does't work:
    Code:
    on OPEN_EXCEL_FILE(inputPath)
    	set wbPath to ((POSIX file inputPath) as string)
    	tell app "Microsoft Excel"
                    set automation security to msoAutomationSecurityForceDisable
                    set display alerts to false
    		set wb to open workbook workbook file name wbPath
    		return name of wb
    	end tell
    end OPEN_EXCEL_FILE
    
     
  2. Hansr macrumors 6502a

    Joined:
    Apr 1, 2007
    #2
    No, you can't block the dialog unless the user explicitly turns it off. Take your mischief elsewhere.
     
  3. Vreditel thread starter macrumors newbie

    Joined:
    Jul 28, 2011
    #3
    Thank you for you answer. But i need to know, what the excel file contains macros. How can I do?
     
  4. Hansr macrumors 6502a

    Joined:
    Apr 1, 2007
    #4
    What do you mean "what the excel file contains macros" ?
     
  5. Vreditel thread starter macrumors newbie

    Joined:
    Jul 28, 2011
    #5
    It's excel file, at opening of which you can see "Enable/Disable Macros" dialog. How i can check the file contains macros before open or another way?
     
  6. Hansr macrumors 6502a

    Joined:
    Apr 1, 2007
    #6
    If it's a .xls you can check the hex stream for the file for 4D 6F 64 75 6C 65 3D if it's in 2007 format then the file extension will be .xlsm.

    If someone has renamed a .xlsm as .xls you can check if it contains 5B 43 6F 6E 74 65 6E 74 5F 54 79 70 65 73 5D 2E 78 6D 6C

    So the logic is:
    Code:
    if (.xlsm) {
    	assume macro
    } else if (.xls) {
    	if (second hex there) {
    		assume renamed -> assume macro
    	} else {
    		if (first hex there) {
    			assume macro
    		}
    	}
    }
     
  7. Vreditel thread starter macrumors newbie

    Joined:
    Jul 28, 2011
    #7
    Thank you, i'm try it tommorow and will write about the result.
     
  8. Vreditel thread starter macrumors newbie

    Joined:
    Jul 28, 2011
    #8
    Hello!!! You example is work, but i need solution on native AppleScript.
     
  9. Vreditel thread starter macrumors newbie

    Joined:
    Jul 28, 2011

Share This Page