Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try
- -- I have no idea why this might fail, but since I found another way, I'll include it.
- tell application "Microsoft Excel" to activate
- on error errMsg number n
- log "activate error..." & errMsg & " with number " & n
- try
- -- I have no idea why this might fail, but since I found another way, I'll include it.
- do shell script "open '/Applications/Microsoft Office 2011/Microsoft Excel.app'"
- on error errMsg number n
- log "do shell script..." & errMsg & " with number " & n
- display dialog "Goodbye. Error. " giving up after 12
- return
- end try -- for do shell script
- end try -- for tell appp "Microsoft Excel"
- delay 5 -- let excel load.
- tell application "Microsoft Excel"
- -- mystery why above tell doesn't work. Was working in the before as it was commented out below.
- try
- -- I have no idea why this might fail, but since I found another way, I'll include it.
- activate
- on error errMsg number n
- log "activate error..." & errMsg & " with number " & n
- display dialog "Activate Error. Continuing. " giving up after 12
- end try -- for do shell script
- try
- -- this sometime fails. Just today. Run again.
- open excelName
- on error errMsg number n
- log "open error..." & errMsg & " with number " & n
- display dialog "Could not open the Excel document. Giving up. Excel should open to a spreadsheet, but sometimes excel wants to be 'helpful' and display something else. " & return & "Suggest you try again. " giving up after 20
- return
- end try
- tell active sheet
- tell used range
- set rowCount to count of rows
- end tell
- -- Is the sheet blank?
- if rowCount > 1 then
- -- sheet not blank, better add stuff at the end.
- else
- -- blank sheet. Insert headers
- -- This is a little odd. Notice how the numbers are going across.
- tell row 1
- set value of cell 1 to "Number"
- set font style of font object of cell 1 to "Bold"
- set value of cell 2 to "Question"
- set font style of font object of cell 2 to "Bold"
- set column width of range 2 to 40
- set value of cell 3 to "Option A"
- set font style of font object of cell 3 to "Bold"
- set value of cell 4 to "Option B"
- set font style of font object of cell 4 to "Bold"
- set value of cell 5 to "Option C"
- set font style of font object of cell 5 to "Bold"
- set value of cell 6 to "Option D"
- set font style of font object of cell 6 to "Bold"
- set value of cell 7 to "Solution"
- set font style of font object of cell 7 to "Bold"
- set column width of range 7 to 40
- set wrap text of range 7 to true
- set value of cell 8 to "Added Date & Time"
- set font style of font object of cell 8 to "Bold"
- set column width of range 8 to 40
- end tell
- tell column 2
- set wrap text to true
- end tell
- tell column 8
- set wrap text to true
- end tell
- end if
- set rowCount to rowCount + 1
- log "rowCount is " & rowCount
- end tell -- active sheet
- end tell -- excel
- -- continuation of example ---------------------------------------------------------------
- -- fill in a row of the excel sheet
- tell application "Microsoft Excel"
- activate
- tell active sheet
- tell row rowCount
- set value of cell 1 to questionActualNumber
- set value of cell 2 to questionText
- repeat with i from 1 to count of answersArray
- set value of cell (2 + i) to item i of answersArray
- end repeat
- -- solution
- set value of cell 7 to answerLetter
- -- date & time
- set value of cell 8 to presentDT
- end tell
- end tell -- active sheet
- end tell -- excel
- log "filled in excel row " & rowCount
- set rowCount to rowCount + 1
- end repeat -- collectionSize
- tell application "Microsoft Excel"
- close workbooks
- quit
- end tell -- excel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement