Wednesday, November 20, 2019

#1 2019-10-21 11:50:56 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3635

Save some datas in an Excel document.

Trying to help an asker elsewhere I wrote :

Applescript:

tell application "Mail"
   # grab a selected message
   set unMessage to item 1 of (get the selection)
   # fill the clipboard with the contents of the message
   set the clipboard to (get content of unMessage)
end tell

tell application "Numbers"
   set monTableur to make new document
   tell monTableur to tell sheet 1 to tell table 1
       # As the default table has an header row
       # and an header column I remove them.
       remove row 1
       remove column 1
       # Define the point where we will paste
       set selection range to range "A1"
   end tell
end tell

tell application "System Events" to tell process "Numbers"
   set frontmost to true
   keystroke "v" using {command down} # Paste the clipboard contents
end tell

set p2d to path to documents folder as text # Edit to fit your needs
set nomDuDoc to "mon tableur.numbers" # Edit to fit your needs
set leChemin to p2d & nomDuDoc as «class furl»

tell application "Numbers"
   save monTableur in leChemin # Save the document
end tell

Alas, the asker is unable to convert the code designed for Numbers to a code driving Excel which I never used.
Is someone here fair enough to write the needed instructions ?

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 21 octobre 2019  19:46:18

Offline

 

#2 2019-10-21 01:53:53 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3635

Re: Save some datas in an Excel document.

Given what I found on the net, assuming that a document is already open, I guess that the code dedicated to Excel would be something like:

Applescript:

tell application "Microsoft Excel"
tell sheet "Sheet1" of workbook 1

# Define the target location where we will paste
set theRange to … # ????
# Paste
paste text range theRange
end tell
end tell

I really don't know how to define theRange.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 21 octobre 2019  21:51:48

Offline

 

#3 2019-10-22 08:24:15 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 720

Re: Save some datas in an Excel document.

Applescript:


tell application "Microsoft Excel"
   tell sheet "Sheet1" of active workbook
       activate object range "A1"
       paste
   end tell
end tell


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#4 2019-10-22 08:26:06 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3635

Re: Save some datas in an Excel document.

Thank you.

I will pass the info to the original asker.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 22 octobre 2019  16:25:59

Offline

 

#5 2019-10-22 08:55:50 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 720

Re: Save some datas in an Excel document.

Entire script.  Like this:

Applescript:


tell application "Mail"
   -- grab a selected message
   set unMessage to item 1 of (get the selection)
   -- fill the clipboard with the contents of the message
   set the clipboard to (get content of unMessage)
end tell

set workbookName to "My Workbook.xlsx"
set destinationPath to (path to documents folder as text) & workbookName

tell application "Microsoft Excel"
   make new workbook
   tell sheet "Sheet1" of active workbook
       activate object range "A1"
       paste
   end tell
   save active workbook in destinationPath
end tell

NOTE: You will be asked for grant to Excel access to Documents folder. So, grant it.

Last edited by KniazidisR (2019-10-22 01:20:20 pm)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#6 2019-10-22 01:37:14 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3635

Re: Save some datas in an Excel document.

Thank you, this time the asker will have all the needed instructions.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 22 octobre 2019  21:37:10

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)