Action "Excel Open Document" is closing document after opening

Discuss RoboTask here
Post Reply
jan
Posts: 26
Joined: Wed Jan 22, 2025 4:36 pm

Action "Excel Open Document" is closing document after opening

Post by jan »

Hello Oleg,

I am trying to open an Excel file and read certain values from the last row. Opening the Excel file works, but it closes immediately after opening. I do not understand this. I am attaching the code:

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|0
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task5"
Hide=INTEGER|0
ID=INTEGER|1912908470
LogOnAsUser=INTEGER|1
Name=STRING|"Excel"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RestrictRESTAPIAccess=INTEGER|0
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
StepPause=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER

[Actions\Action1]
ActionID=STRING|"A_EXCEL_OPEN"
Enabled=INTEGER|-1
Name=STRING|"Excel Open Document"
Params=FOLDER

[Actions\Action1\Params]
filename=STRING|"Z:\BIZ\ECO\Contract\25\2025_Contract_Managment.xlsm"
hide=STRING|"0"
mode=STRING|"0"
tryconnect=STRING|"1"

[Actions\Action2]
ActionID=STRING|"A_EXCEL_GET"
Enabled=INTEGER|0
Name=STRING|"Excel Get Cells"
Params=FOLDER

[Actions\Action2\Params]
cell00000000=STRING|"22"
count=STRING|"1"
var00000000=STRING|"jb"
worksheet=STRING|"1"
Oleg
Site Admin
Posts: 3175
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Action "Excel Open Document" is closing document after opening

Post by Oleg »

If you open a document in a task, the task closes the document when the task is finished.
Use Run Program/Open Document. Also put some pause after it. EXCEL must have a time to open document.
Then, you can connect to already opened document by Excel Open Document action
Oleg Yershov
jan
Posts: 26
Joined: Wed Jan 22, 2025 4:36 pm

Re: Action "Excel Open Document" is closing document after opening

Post by jan »

Hello Oleg,

Thank you very much. Now I would like to read all cells from column A whose cell content begins with DE01 or SK01 or SK02 or SK03. For each of the above cells in column A, I would like to read all the cells in column B.

Column A Column B
DE012014070 ENDR
EN012016022 STEL
DE012019014 STAU
SK032020012 ERLA
SK012020024 ALTO

These values are to be saved in a CSV file.

EN012014070;ENDR
EN012016022;STEL
EN012019014;STAU
SK032020012;ERLA
SK012020024;ALTO

The CSV file is to be cleaned of duplicates.

Is that possible and could you help?


Best regards, Ján
Oleg
Site Admin
Posts: 3175
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Action "Excel Open Document" is closing document after opening

Post by Oleg »

I would like to read all cells from column A whose cell content begins with DE01 or SK01 or SK02 or SK03.
Why does your example of CSV contain EN01 lines?
EN012014070;ENDR
EN012016022;STEL
EN012019014;STAU

SK032020012;ERLA
SK012020024;ALTO
Oleg Yershov
jan
Posts: 26
Joined: Wed Jan 22, 2025 4:36 pm

Re: Action "Excel Open Document" is closing document after opening

Post by jan »

Hello Oleg,

unfortunately that was my mistake.

Column A Column B
DE012014070 ENDR
DE012016022 STEL
DE012019014 STAU
SK032020012 ERLA
SK012020024 ALTO

Analog in the CSV file:

DE012014070;ENDR
DE012016022;STEL
DE012019014;STAU
SK032020012;ERLA
SK012020024;ALTO
Oleg
Site Admin
Posts: 3175
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Action "Excel Open Document" is closing document after opening

Post by Oleg »

look at my example below.
... all cells from column A whose cell content begins with DE01 or SK01 or SK02 or SK03
In this case it's better to use regular expressions. This is universal method

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task19"
Hide=INTEGER|0
ID=INTEGER|-402748910
LogOnAsUser=INTEGER|1
Name=STRING|"Load XLS and make CSV"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RestrictRESTAPIAccess=INTEGER|0
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
StepPause=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action13=FOLDER
Action14=FOLDER
Action15=FOLDER
Action16=FOLDER
Action17=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""xlsDoc"" with value ""C:\temp\csv\Book1.xlsx"""
Params=FOLDER

[Actions\Action1\Params]
_rt_variables_produced=STRING|"xlsDoc"
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"xlsDoc"
varvalue=STRING|"C:\temp\csv\Book1.xlsx"

[Actions\Action10]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action11]
ActionID=STRING|"A_REGEXP_MATCH"
Enabled=INTEGER|-1
Name=STRING|"RegExp Match \\ begins with DE01 or SK01 or SK02 or SK03 only"
Params=FOLDER

[Actions\Action11\Params]
_rt_variables_produced=STRING|"match"
anchored=STRING|"0"
case=STRING|"0"
extended=STRING|"0"
line00000000=STRING|"{a_cell}"
linecount=STRING|"1"
multiline=STRING|"0"
noautocapture=STRING|"0"
pattern=STRING|"^(DE01|SK01|SK02|SK03)"
savesubexpression=STRING|"0"
singleline=STRING|"0"
subexpressionpos=STRING|"0"
ungreedy=STRING|"0"
useexternal=STRING|"0"
variable=STRING|"match"

[Actions\Action12]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action12\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{match}"

[Actions\Action13]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""CSV"" with value ""{CSV}{a_cell};{b_cell}{eol}"""
Params=FOLDER

[Actions\Action13\Params]
_rt_variables_produced=STRING|"CSV"
expand=STRING|"1"
linecount=STRING|"1"
varname=STRING|"CSV"
varvalue=STRING|"{CSV}{a_cell};{b_cell}{eol}"

[Actions\Action14]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action15]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

[Actions\Action16]
ActionID=STRING|"A_EXCEL_CLOSE"
Enabled=INTEGER|-1
Name=STRING|"Excel Close"

[Actions\Action17]
ActionID=STRING|"A_DIALOG_SHOWTEXT"
Enabled=INTEGER|-1
Name=STRING|"Show Text"
Params=FOLDER

[Actions\Action17\Params]
autoclose=STRING|"0"
fromfile=STRING|"1"
line00000000=STRING|"{CSV}"
linecount=STRING|"1"
timeout=STRING|"10"

[Actions\Action2]
ActionID=STRING|"A_EXCEL_OPEN"
Enabled=INTEGER|-1
Name=STRING|"Excel Open Document"
Params=FOLDER

[Actions\Action2\Params]
filename=STRING|"{xlsDoc}"
hide=STRING|"0"
mode=STRING|"0"
tryconnect=STRING|"0"

[Actions\Action3]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""num"" with value ""1"""
Params=FOLDER

[Actions\Action3\Params]
_rt_variables_produced=STRING|"num"
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"num"
varvalue=STRING|"1"

[Actions\Action4]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""CSV"" with value """""
Params=FOLDER

[Actions\Action4\Params]
_rt_variables_produced=STRING|"CSV"
expand=STRING|"0"
linecount=STRING|"0"
varname=STRING|"CSV"

[Actions\Action5]
ActionID=STRING|"A_LOOP_WHILE"
Enabled=INTEGER|-1
Name=STRING|"While loop"
Params=FOLDER

[Actions\Action5\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"true"

[Actions\Action6]
ActionID=STRING|"A_EXCEL_GET"
Enabled=INTEGER|-1
Name=STRING|"Excel Get Cells"
Params=FOLDER

[Actions\Action6\Params]
cell00000000=STRING|"A{num}"
cell00000001=STRING|"B{num}"
count=STRING|"2"
var00000000=STRING|"A_cell"
var00000001=STRING|"B_cell"
worksheet=STRING|"1"

[Actions\Action7]
ActionID=STRING|"A_VARIABLES_INCREMENT"
Enabled=INTEGER|-1
Name=STRING|"Increment variable ""num"""
Params=FOLDER

[Actions\Action7\Params]
incement=STRING|"1"
vaiable=STRING|"num"

[Actions\Action8]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action8\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"7"
type=STRING|"0"
value1=STRING|"{a_cell}"

[Actions\Action9]
ActionID=STRING|"A_LOOP_BREAK"
Enabled=INTEGER|-1
Name=STRING|"Break"
Oleg Yershov
Post Reply