Rename and save a read only Excel file

I’m trying to make and applescript folder action that would open and Excel file when added to a folder. I need the Excel file to be opened as Read Only and i am having problems with that. Also the file is to be renamed so it can be saved. The version of Excel that i am using is 2008.
This is what i have so far. It works up till it needs a keystroke to accept the read only.
Any help would be appreciated.
PolishPrince



on adding folder items to this_folder after receiving added_items
	
	set the_path to (POSIX path of this_folder) as string
	try
		tell application "Finder"
			set theFile to added_items as string
		end tell
		
		--Separate the filename from the Posix Path
		set myString to theFile
		set AppleScript's text item delimiters to ":"
		set TheItemList to every text item in myString
		set AppleScript's text item delimiters to ""
		--set theNewString to every item in TheItemList as string
		set theNewString to the last item in TheItemList as string
		
		--Open the file in Excel, rename, save and quit
		tell application "Microsoft Excel"
			activate
			
			--open workbook workbook file name myFile
			open workbook workbook file name theNewString
			
			--Force a Return Keystroke to the default Read Only button
			tell application "System Events" to tell process "Microsoft Excel" to keystroke return
			
			activate object worksheet "Sheet1"
			
			--Change the name of the file to be resaved
			set theNewString to ("New" & theNewString)
			
			save active workbook in the_path
			close active workbook
		end tell
		
		
	end try
end adding folder items to


Have you tried changing the open line

open workbook workbook file name theNewString with read only

Also, why fiddle with the read-only setting if you’re just going to close the workbook before the user can get to it?

Mikerickson
The reason i am doing this is to change the name so it can be opened from an Iphone. The file can’t be opened remotely from and iphone when it is locked. I have a mail rule to send an Excel attachment to a folder that is going to have this folder action.
If this folder action could open the file in read only then maybe it could be saved with another name. I don’t know a lot about Applescript but, i really enjoy learning about it.
Thanks for your reply, i am going to try your suggestion.
Polishprince

Have you considered having Finder duplicate and re-name the file, rather than saving it through Excel?

Mikerickson
I’m not so good in Applescript and i don’t know how to Duplicate and re-name a file but, i think that just to re-name the file will take the locking on the file with it. That is why i wanted to open in Excel and re-save in another name.
It would be great if someone could show me or point to an example of how this is done. I searched through the archive and none of the examples seem to work for me.
Thank you for your interest
Polishprince

Hi
I’m still tearing my hair out trying to get a return keystroke. If i put my keystroke code before the line below, it doesn’t do anything and if i put it after, it is to late. Is it possible that i could put the open workbook and the code to keystroke on the same line. Any help would be greatly appreciated.
Thanks
Polishprince


--Force a Return Keystroke to the default Read Only button
 open workbook workbook file name theNewString