Thank you all–
take318: Yes, I do use properties. I don’t have to. I thought that was the best way to dim global variables, but I can change in a heartbeat. I’ll do so, and see what’s what. Why does this come to mind?
McUsrlll: Other than the topic, my code performs as I want when open in the editor, but here’s the top of it. The display dialog part runs. The “copy to the clipboard” part does not. When it works, it does a “Select All” then a “Copy” giving the visual feedback of everything as selected. Not so when closed.
property TabSize : 3 -- spaces per tab. Adjust to suit
property AlignDimAsToTabs : true -- Adjust to suit
property PutDimAsAtTab : 7 -- Adjust to suit
property NoTabs : {"Option Explicit", "Option Base", "Option Compare", "Sub", "Private", "Public", "Function", "Type", "Enum", "End Sub", "End Function", "#Const"}
property OneTab : {"Const", "Dim", "ReDim", "Static", "Stop", "Debug", "#If", "#Else", "#End"}
property PushTabs : {"For", "With", "Do", "Select", "Case"}
property IfTabs : {"If", "Else", "End If"} --Push, Pop & Push, Pop
property PopTabs1Word : {"Next", "Loop"}
property PopTabs2Words : {"End With", "End Select"}
property LineLeads : {"&", quote, "DQ"}
property MSExcel : true
set OldCode to ""
set NewCode to ""
set templine to ""
set Tabs to 0
set Stack to {1}
set CaseStack to {}
set TempStack to {}
set ThisLine to {}
set EqualsPosit to 0
set the clipboard to OldCode --This step works
display dialog "Please pick your application." buttons {"Cancel", "MS Word", "MS Excel"} cancel button 1 default button 3 with icon caution
if result is {button returned:"MS Excel"} then
set MSExcel to true
set AppProcess to "Microsoft Excel"
tell application id "com.microsoft.Excel" to activate
else
set MSExcel to false
set AppProcess to "Microsoft Word"
tell application id "com.microsoft.Word" to activate
end if
tell application "System Events" --This step only runs when open in the editor.
tell application process AppProcess --scripting the GUI
set frontmost to true
set myList to (get name of windows)
repeat with i from 1 to count of myList
try
if last word of item i of myList is "Code" then
perform action "AXRaise" of window i
exit repeat
end if
end try
end repeat
end tell
keystroke "a" using command down
delay 1
keystroke "c" using command down
delay 1
--if nothing happens, make sure your code window is frontmost.
end tell
...lots more code processing the clipboard. Ends with a paste back.
I call the code from this script:
run script file "Macintosh HD 10.6:Applications:AppleScript:VBE.scpt"
Thanks, Mick