Yes so the point of tue macro is.. if entity is X and Client is Y, pull this time sheet (local drive). In the top 3 fields, enter name - employee ID, classification.
Save as using the naming variable (string) to a different folder (for backup and tracking purposes)
Email that file
It needs to be save as (or similar) because the original file needs to be clean for the next worker that ends up pulling that timesheet.
My company has 2 entities. Within those entities, like 30 clients. I used your help in the beginning of when it was parsing an email for variables. Two of those variables dictate the document that gets pulled. The other variables for filling in the doc with that workers info.
Excel is scriptable. You can do something like this:
l --------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2022/11/08 20:00
# dMod: 2022/11/11 00:03
# Appl: Microsoft Excel
# Task: Create New Workbook and Save With a Specific Name In a Specific Folder.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Microsoft_Excel
# Vers: 1.01
--------------------------------------------------------
use AppleScript version "2.4" --» Yosemite or later
use framework "Foundation"
use scripting additions
--------------------------------------------------------
# Path to Excel template file:
set templateFile to "~/Desktop/test.xlsx"
set templateFile to ((current application's NSString's stringWithString:templateFile)'s stringByExpandingTildeInPath) as text
# Create new path for temporarily saved version of modified template file (to be emailed).
set saveDir to path to desktop folder as text
set newExcelFilePath to saveDir & "New Workbook Name.xlsx"
tell application "Microsoft Excel"
activate
# Open the template.
open templateFile
# Save a temporary working version to a new location.
# (You may have to authorize Excel to use this location.)
save active workbook in newExcelFilePath
tell active sheet
set value of cell "A1" to "Philip"
set value of cell "B1" to "Marlowe"
set value of cell "C1" to "Private Eye"
end tell
save active workbook
close front window
end tell
--------------------------------------------------------
Howdy. Revisiting this thread because I have an issue that uses what we spoke about here.
I am using regex (supplied by @Nige_S) to pull a string from a variable.
The problem is on my companies end, not KM. But if it is solvable on my end (KM), awesome.
Background - We have Job titles (class) that the client has entered an extra space after the title. When trying to enter this info into a data validated cell in Excel, it won't allow because of that extra space after the classification. The string pulled by regex (saved to local_Class) doesn't contain that extra space because the user doesn't see it when applying the information for the regex to grab.
My hope - Is there a way to do input into excel, give or take a space, when there is a data validation drop down with preset entries?
The best way to sort this is at data entry -- those titles should be validated when the client enters them originally, for example by only allowing them to choose titles from a preset list or by trimming leading/trailing spaces on submission.
But I'm guessing you have little control of that stage I'm also guessing that if they put in trailing spaces, they might also fat-finger leading spaces...
So if you want to "extract the text from local_NHF, minus any leading or trailing spaces" you have (at least) two approaches:
Use the "Search" you already have, but then apply a "Filter" action to local_Class -- one of the filters is "Trim Whitespace", which will do just what you want.
Change your Regular Expression so it matches the potential extra spaces but doesn't capture them. The front spaces are easy -- \s* for "zero or more whitespace characters, but you can't do just that for the trailing because even it it finds a space the preceding (.*) is greedy and will have matched it first. Changing that to match "everything but a space" might help, but will break if you have two-word titles.
Instead we can change it to a non-greedy (or lazy) match -- (.*?) -- which lets the final \s* gobble up as many spaces as it can, leaving none for our capture group. So
(?m)^Class:\s*(.*?)\s*$
...will capture the job title, without any reading or trailing spaces if they are present, and the result should validate in your spreadsheet.
Try both, with and without the ? and with and without the extra spaces, in https://regex101.com to see how this works.