Jump to content

Pick data from excel and add to string


Recommended Posts

I have the below script where the sequence is very important as the 1st Script generates a log file and then the 2nd Script uses the value from the log file as the loop counter.

Here is the what I want and the sequence

Script 1

1-  Send("S*D/<The value here should come from cell A1 of excel workbook data.xlsx>/17AUG/US") so the keystrokes sent would be e.g. S*D/321/17AUG/US (321 was the value in excel cell A1)

Script 2

2- After Script 1 is complete, Script 2 performs its actions which is sending formats in a loop a certain number of times

3- Once Script 2 completes its actions, I want to go back to Script 1 and this time pick data from Cell A2 of the excel workbook and perform its actions

4- This loop continues till there is no more cells with a value in column A of Excel workbook

;Script 1
#include <MsgBoxConstants.au3>

WinActivate("Application")
WinWaitActive("Application")

Send("S*D/$Value from Excel$/17AUG/US")
Sleep(1000)
Send("{ENTER}")
Sleep(2000)
Send("MB")
Sleep(1000)
Send("{ENTER}")
Sleep(3000)

Script2()
Func Script2()
    Local $iPID = Run("Script2.exe")
EndFunc

;Script2
#include <MsgBoxConstants.au3>

$file = @ScriptDir & "\T.log"

$iNum = StringRegExp(FileRead($file), "(?sm).*^\h*(\d{1,3})", 1)[0]
ConsoleWrite($iNum & @CRLF)

WinActivate("Application")
Local $hWnd = WinWaitActive("Application", "", 5)

If $hWnd Then
    For $i = 1 To $iNum
        Send("GTIM"& $i &"/OVR")
        ;Send("GTIM"& $i &"/OVR "{ENTER}"")
        Sleep(1000)
        ;Send("/OVR")
        Send("{ENTER}")
        Sleep(1000)
    Next
Else
    MsgBox(0, "", '"Application" window not found.')
EndIf

 

Link to comment
Share on other sites

12 hours ago, Vikramjeet said:

I would love to. I started with AutoIt 1 week ago. I have no knowledge or experience of writing scripts. I will work on your suggestion. Thank you for your guidance 

You request a lot of coding from other in multiple posts.... Even if we help you* You dont try anything. Exept CTRL - C , V . Try to learn at le@st.

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

I have managed to capture cell value from Column A, row 1, 2, 3, 4........without opening the excel file. The script makes a certain 'Application' active. Now instead of showing the cell values in a pop up message, I want the script to send it as key strokes to the 'Application'. How can I achieve this

$oExcel = ObjCreate("Excel.Application")
$oExcel.Visible =  0

WinActivate("Application")
WinWaitActive("Application")

If IsObj($oExcel) Then
   For $a = 1 to 5
   $oExcel.Application.WorkBooks.Open("C:\Users\Charlie\Desktop\Data.xlsx")
      msgbox(1 ," ", $oExcel.Application.Cells($a,1).Value )
   Next
EndIf

 

Link to comment
Share on other sites

You open the Excel workbook but do not see it as it is being done invisible :) 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

3 minutes ago, FrancescoDiMuro said:

@Vikramjeet

How can you see what there is in a box without open it?

 

This script is reading the cell values and doing exactly what I want. Now I need to close the excel file and set the loop to end when the row is blank

$oExcel = ObjCreate("Excel.Application")
$oExcel.Visible =  0

WinActivate("Application")
Local $hWnd = WinWaitActive("Application", "", 5)

$oExcel.Application.WorkBooks.Open("C:\Users\Charlie\Desktop\Data.xlsx")

If $hWnd Then
   For $a = 1 to 5
      Send("S*D/"& $oExcel.Application.Cells($a,1).Value &"'US/NYC")
      Sleep(1000)
      Send("{ENTER}")
      Sleep(3000)
   Next

EndIf

 

Link to comment
Share on other sites

  • 2 weeks later...
$oExcel = ObjCreate("Excel.Application")
$oExcel.Visible =  0
#include <MsgBoxConstants.au3>

WinActivate("Application")
Local $hWnd = WinWaitActive("Application", "", 5)

$oExcel.Application.WorkBooks.Open("C:\Users\Charlie\Desktop\Data.xlsx") ;Opens the excel file. I need to close it at the end of the script
local $iCell = $oExcel.Application.Cells(31,1).Value

If $hWnd Then
   For $a = 1 to $iCell
      Send("S*D/")
      Send($oExcel.Application.Cells($a,1).Value)
      Send("'DUL/SX*E")
      Sleep(1000)
      Send("{ENTER}")
      Sleep(3000)
      Send("MB")
      Send("{ENTER}")
      Sleep(3000)
      
$file = @ScriptDir & "\T.log"

$iNum = StringRegExp(FileRead($file), "(?sm).*^\h*(\d{1,3})", 1)[0]
ConsoleWrite($iNum & @CRLF)

If $hWnd Then
    For $i = 1 To $iNum
        Send("DSIM"& $i &"/AST")
        Sleep(2000)
        Send("{ENTER}")
        Sleep(2000)
    Next
Else
    MsgBox(0, "", '"APPLICATION" window not found.')
EndIf
Next
EndIf

I have the above script which opens an excel file as not visible. I need to add a line to close it at the end of the script so the user does not have to do that

Link to comment
Share on other sites

Why don't you use the Excel UDF that comes with AutoIt. See functions _Excel_Open, _Excel_BookOpen, _Excel_RangeWrite, _Excel_BookClose and _Excel_Close.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Also if you got a process that is open you can easily close it.

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...