Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Vreditel

macrumors newbie
Original poster
Jul 28, 2011
11
0
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
 
No, you can't block the dialog unless the user explicitly turns it off. Take your mischief elsewhere.
 
Thank you for you answer. But i need to know, what the excel file contains macros. How can I do?
 
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?
 
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
		}
	}
}
 
Thank you, i'm try it tommorow and will write about the result.
 
Hello!!! You example is work, but i need solution on native AppleScript.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.