Clicking Field with AutoIt in an ERP program - automation

Here is my scenario:
I am starting AutoIT recorder. I record using the keyboard since using the mouse causes the script to stop most of the time or does something inaccurate when started after that.
What I do is I open up an Excel template I have created. I then go into an ERP system and copy a few columns which I paste into Excel. After these columns are inserted, a few more columns are calculated from the formulas I have previously inserted.
The problem is that when I am into the ERP system I have selected a specific time period...Let's say 1st November till 31st November. I then save the excel and use the Excel option to send an email to specific people with the excel report attached.
I compile the autoit script to an exe and I have a scheduler which starts the exe. The problem is that I need a way to change the date to December, then January and so on... How do I do that using AutoIt? Can it be done at all?
This is how the date looks like in the ERP program:

You need to first inspect the program using AutoIt Window Info tool: drag the target icon to the filed you wish to click on - use ControlClick. Let's take an example with Excel, it says the title is: "Book1 - Excel" and the ID of the button I chose is "1001", the script will be:
ControlClick("Book1 - Excel", "", 1001)
If there isn't any ID, it will be harder as you'll need to MouseClick by coordinates which is prone for errors...
Changing the time: in order to change the date picking according to the current month you'll need something like:
Local $stringInCell = ControlGetText("ERP title", "text in ERP window (can be empty)", controlID)
If #MON = StringLeft($stringInCell, 2) Then
ControlClick("ERP title", "text in ERP window (can be empty)", controlID)
EndIf
Where #MON is a macro, and StringLeft is like starts with, assuming the first 2 characters are good for you (e.g. January is 01).

Related

In excel VBA, I am looking for VBA code that adds a new line item with the latest month end each time the spreadsheet opens

I currently have a spreadsheet that has individual line items for each month end. Starting in A1, 1/31/2021 and A5, 5/31/2021 for example. My goal is, each month when I open the spreadsheet, a new line item is created for that month; so if it's 5/21/2021 and I open the spreadsheet, it will create a line item with 5/31/2021. Is it possible to include logic that checks the current month I'm in and will open add a line item if it's relevant for the appropriate month?
Screenshot/here refer:
(note - for security reasons, linked sheet above has not VB code - this needs to be built in as described below).
High level
This soln. requires following: 2 named ranges, macro-enabled workbook. Office 365 not necessary.
Setup
Enter any date you wish in column A (max capacity = 100)
Ranges
Create named formula: Formulas | Name Manager | New… set name = 'dates'; enter formula: =$A$1:OFFSET($A$1,COUNTA(1,1000)-1,0,1,1)
(This is a dynamic (automatically grows to accommodate your list of dates in column A)
As for 2) but with following: name : 'Required' (w/ apostrophes), formula = =IFERROR(IF(YEAR(INDEX(dates,MATCH(MONTH(TODAY()),MONTH(dates),0)))=YEAR(TODAY()),0,1),1)
(this creates a formula that checks whether any of the dates in col A already have the current month. i.e. 'Required' = 0 if month already exists (for current year); else 1 returned)
VB
Let the fun begin!
Alt + F11 (open VB for Excel running on Windows)
Locate your file in the Project Explorer (typically default window pane on left hand side; if no such pane, then select from the upper ribbon/menu bar: View | Project Explorer:
Double click the component entitled 'ThisWorkbook' to reveal a new window pane on the right-hand side of the VB window.
The remaining operations appertain to the VB window pane on the Right Hand Side (RHS)...
There are two menu bars with drop-down functionality at the top of the VB-code pane:
Left drop-down / Right drop-down - select respective drop-downs as 'Workbook' and 'Open' respectively, then enter the code per below screenshot (code replicated here for convenience):
Code
Private Sub Workbook_Open()
REQ = Application.Evaluate("Required")
Range("f5").Value = REQ
If REQ = 1 Then
new_date = Format(Date, "dd/mm/yyyy")
Sheets("68516961").Range("dates").Offset(1).Value = new_date
End If
End Sub
Voila! You're all set to go! I tested a couple of times and all appears to be working fine. fyi - don't forget to save as macro-enabled workbook (I prefer .xlsb files as the typically have half the file size compared to .xlsm - the one exception I'm aware of is if there is an SQL connection - in which case it's about the same size as the .xlsm counterpart)...
Functionality:
Every time you open the workbook, the VB code is run - it checks to see if there are any dates that comprise the same month and year as the day your opening the file; if not, the date of 'that day' is automatically populated at the bottom of any existing list of dates in A:A. This gives you the freedom of being able to include other / manually entered dates or otherwise between successive VB created date appended values.
Appendices
Creating named ranges:

Change schedule date format

I'm working in MS Project where the entire project duration is one hour.
My goal is to run a VBA sub when the program opens, to format the project schedule date to the "12.33 pm" style.
I've searched https://learn.microsoft.com/en-us/office/vba/api/project.application.dateformat to find a solution, but can't figure out the right syntax.
DateFormat(ActiveProject.Tasks) = pjDate_pjDate_hh_mmAM
I'd like to call this macro from my "open on macro" so the schedule date format changes to "pjDate_hh_mmAM".
The setting you are looking for is the DefaultDateFormat property of the Application object. This is the equivalent of going to File: Options, General tab: Date format.
Application.DefaultDateFormat = pjDate_hh_mmAM
You might consider capturing the current setting and restoring it later as it is an application-level setting and all projects opened will reflect this date format.

Where do I insert this code to create the macro in CorelDraw X7?

I'm referring to this post here:CorelDraw X6 Macro to insert Date using DTPicker Control
I am creating a template for everyday use for saving artwork proofs to send onto customers for visual approval. I'd like the following boxes to auto populate the following information:
1. A box that will populate today's date
2. A box that will populate the work order number based on the first 6 digits of the filename
3. A box that will populate the filename as a whole
The rectangles/boxes will already be in the document that gets imported. I just want to create a macro, or multiple...to click in order to fill these boxes before exporting to a PDF for customers approval.
I'm a total coding n00b and can't find specific directions on where to copy the code listed in the link above.
In the Corel Draw menu, go to "Tools" then "Macros" then "Macro editor".
After that, you can paste it in the right hand side of the screen, on the white empty box.
That should do it.

Outlook : How to automate task

I have 1000s of "Tasks" and "Appointments" created for testing purposes. They all are copied and pasted from one message that I have created manually hence it contains same values in Objects like "Start Time" & "End Time" and Status as "In Progress" ...
I would like to change these dates, start, end time & status progress to random values - (It is required to test the search criteria of our product i.e. to assure the our search logic can handle variation of different dates and option provided for search and so forth.)
I know I can automate it by using VBA. I have enabled the developer tab but how to get to go through the list, open each task, change the data in required field, save task & move on to next until done with the full list.
VBA code for getting the tasks:
http://www.gregthatcher.com/Scripts/VBA/Outlook/GetListOfTasks.aspx
http://www.jpsoftwaretech.com/get-ting-outlook-items-through-vba/
Use combination of both links provided
Courtesy goes to original authors. Just found these as first hits on google.

Google Apps Script on Form Submit Time Formatting Glitch/Fix

Background:
How: I suspect that this is a glitch within Google Form (submission process)/Spreadsheet, but may be part of the Date conversion utility of the Spreadsheet interface (and is an intended feature).
When entering a format in a text box in Google Forms, there is some sort of communication error between the Form submit and Response Spreadsheet, or pre-processing of the Form's data before it is sent to the spreadsheet. The glitch only seems to happen for data in a text field of the format ##:## TEXT where TEXT contains no '.' characters. For example: 4:15 pm will reproduce the glitch, but 4:15 p.m and 4:15 p.m. will not.
Result: An apostrophe character is added to the beginning of the string when it is put into the Spreadsheet (i.e. '4:15 pm) which throws off several sub-systems I have in place that use that time data. Here are two screenshots (sorry for the bad sizing on the second):
I'm 99% certain that the glitch is caused by the ##: combination.
Temporary Fix?: The real question is... how might I go about removing that pesky apostrophe before I start manipulating the time data? I know how to getValue() of a cell/Range. Assume I have the value of a cell in the following manner:
var value = myRange.getValue();
// value = '4:15 pm
How can I go about processing that value into 4:15 pm? A simple java function could be
value = value.substring(1); // Assuming "value" is a String
But in Google App Scripts for Spreadsheets, I don't know how I would do that.
Post-Script: It is necessary to post-process this data so that I don't have to lecture university faculty in the language department about inputting time format correctly in their forms.
Thanks in advance to those who can help!
How can I go about processing that value into 4:15 pm? A simple java
function could be
value = value.substring(1); // Assuming "value" is a String But in
Google App Scripts for Spreadsheets, I don't know how I would do that.
Google Apps Scripts uses Javascript which has the exact same method.
value = value.substring(1);
should return all except the first character.
More about Javascript substring at: http://www.w3schools.com/jsref/jsref_substring.asp
If you remove the ' in the spreadsheet cell the spreadsheet interface will convert this entry to a date object.
This might (or not) be an issue for you so maybe you should handle this when you read back your data for another use...
It doesn't happen when text is different (for example with P.M) simply because in this case the ' is not necessary for the spreadsheet to keep it as a string since the spreadsheet can't convert it to a date object (time value).
Artificial intelligence has its bad sides ;-)
edit :
You cant do this in an onFormSubmit triggered function using the javascript substring() you mentioned. If you're not familiar with that, here is the way to go :
To run a script when a particular action is performed:
Open or a create a new Spreadsheet.
Click the Unsaved Spreadsheet dialog box and change the name.
Choose Tools > Script Editor and write the function you want to run.
Choose Resources > Current project's triggers. You see a panel with
the message No triggers set up. Click here to add one now.
Click the link.
Under Run, select the function you want executed by the trigger.
Under Events, select From Spreadsheet.
From the next drop-down list, select On open, On edit, or On form
submit.
Click Save.
see doc here and here