• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Excel insanity
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Excel insanity


  • Subject: Re: Excel insanity
  • From: David Crowe via AppleScript-Users <email@hidden>
  • Date: Fri, 3 Apr 2020 13:59:29 -0600

To close off this discussion, the following code works nicely:

tell application "Microsoft Excel"
        open workbook workbook file name
"/Users/david/Documents/TheInfectiousMyth/Marketing/Update Email List.xlsx"
        tell workbook "Update Email List.xlsx"
                tell worksheet "TIM Emails"
                        -- Bail if already here
                        set searchRange to range ("C2:C9999")
                        try
                                set foundRange to find searchRange what
theEmailAddress
                                -- If the email address is not present an error
will mean that the following code is not executed
                                tell me
                                        activate
                                        display dialog "Email address <" &
theEmailAddress & "> already in file" giving up after 3
                                        return
                                end tell
                        end try
                        -- Find first blank row
                        set blank to ""
                        set searchRange to range ("C2:C9999")
                        set foundRange to find searchRange what blank
                        set theRow to first row index of foundRange as text
                        set value of cell ("A" & theRow) to FirstName
                        set value of cell ("B" & theRow) to LastName
                        set value of cell ("C" & theRow) to theEmailAddress
                        set value of cell ("D" & theRow) to DateString
                        set value of cell ("E" & theRow) to "Email"
                end tell
                save
        end tell
end tell



The trick is the “open workbook” line. Even if the workbook is already open, it
brings it to the front, and if the workbook is on the front, and “tell
worksheet”  is processed correctly (it does not suffer from the same bug), so
even if “TIM Emails” is not the frontmost worksheet, the script still operates
on it.

This may be a useful workaround for anyone else who uses “tell workbook” and
then Excel operates on the wrong workbook.

This is not a perfect solution, I don’t know what would happen if another
workbook was brought to the front during the execution of the script, but
luckily that’s not too likely.

Thanks for  all the suggestions everyone.

- David Crowe
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Detecting scroll to bottom of alert text
  • Next by Date: Problem with Special Cells
  • Previous by thread: Detecting scroll to bottom of alert text
  • Next by thread: Problem with Special Cells
  • Index(es):
    • Date
    • Thread