Open Excel in Background using Task Scheduler

Viliam Popovec <[email protected]> Fri, 28 Jun 2024 11:38:23 +0200
Newsgroups gmane.comp.python.windows
Message-ID <CAHJiA-=i3jsy-OKu=fyeFt-evjhmL5mzhn_+ZgvsA_2fFb1TMQ@mail.gmail.com>
--===============1519499825384899232==
Content-Type: multipart/alternative; boundary="000000000000e8c318061bf00204"

--000000000000e8c318061bf00204
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hello,

I have a Windows VM running in Azure cloud, which is connected to File
Shares. I have created a Python script which downloads the excel files from
the file shares, executes macros and copies the files back. I am able to
get this working with a "foreground" task, i.e. launching the script when
logged on. However I need to automate launching of the script in case that
the VM is restarted, for this I am using Task Scheduler.

Task Scheduler works when running in the foreground, but when I select the
option "run whether user is logged on or not" I receive the following error
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft
Excel', "Microsoft Excel cannot access the file
'C:\\AMS\\temp_dir\\Auftragsnummernliste.xlsm'. There are several possible
reasons:\n\n=E2=80=A2 The file name or path does not exist.\n=E2=80=A2 The =
file is being
used by another program.\n=E2=80=A2 The workbook you are trying to save has=
 the
same name as a currently open workbook.", 'xlmain11.chm', 0, -2146827284),
None) from this line of code excel_macro.Workbooks.Open(Filename=3Dfile_pat=
h,
ReadOnly=3D1)

Is there a way to open the excel file in the background or do I have to
find some other workaround (e.g. alerting the admin that the VM was
restarted).

--000000000000e8c318061bf00204
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello,=C2=A0<div><br></div><div>I have a Windows VM runnin=
g in Azure cloud, which is connected to File Shares. I have created a Pytho=
n script which downloads the excel files from the file shares, executes mac=
ros and copies the files back. I am able to get this working with a &quot;f=
oreground&quot; task, i.e. launching the script when logged on. However I n=
eed to automate launching of the script in case that the VM is restarted, f=
or this I am using Task Scheduler.</div><div><br></div><div>Task Scheduler =
works when running in the foreground, but when I select the option &quot;ru=
n whether user is logged on or not&quot; I receive the following error pywi=
ntypes.com_error: (-2147352567, &#39;Exception occurred.&#39;, (0, &#39;Mic=
rosoft Excel&#39;, &quot;Microsoft Excel cannot access the file &#39;C:\\AM=
S\\temp_dir\\Auftragsnummernliste.xlsm&#39;. There are several possible rea=
sons:\n\n=E2=80=A2 The file name or path does not exist.\n=E2=80=A2 The fil=
e is being used by another program.\n=E2=80=A2 The workbook you are trying =
to save has the same name as a currently open workbook.&quot;, &#39;xlmain1=
1.chm&#39;, 0, -2146827284), None) from this line of code=C2=A0<span style=
=3D"font-family:&quot;JetBrains Mono&quot;,monospace;font-size:9.8pt;backgr=
ound-color:rgb(30,31,34);color:rgb(188,190,196)">excel_macro.Workbooks.Open=
(</span><span style=3D"font-family:&quot;JetBrains Mono&quot;,monospace;fon=
t-size:9.8pt;background-color:rgb(30,31,34);color:rgb(170,73,38)">Filename<=
/span><span style=3D"font-family:&quot;JetBrains Mono&quot;,monospace;font-=
size:9.8pt;background-color:rgb(30,31,34);color:rgb(188,190,196)">=3Dfile_p=
ath, </span><span style=3D"font-family:&quot;JetBrains Mono&quot;,monospace=
;font-size:9.8pt;background-color:rgb(30,31,34);color:rgb(170,73,38)">ReadO=
nly</span><span style=3D"font-family:&quot;JetBrains Mono&quot;,monospace;f=
ont-size:9.8pt;background-color:rgb(30,31,34);color:rgb(188,190,196)">=3D</=
span><span style=3D"font-family:&quot;JetBrains Mono&quot;,monospace;font-s=
ize:9.8pt;background-color:rgb(30,31,34);color:rgb(42,172,184)">1</span><sp=
an style=3D"font-family:&quot;JetBrains Mono&quot;,monospace;font-size:9.8p=
t;background-color:rgb(30,31,34);color:rgb(188,190,196)">)</span></div><div=
><br></div><div>Is there a way to open the excel file in the background or =
do I have to find some other workaround (e.g. alerting the admin that the V=
M was restarted).</div></div>

--000000000000e8c318061bf00204--

--===============1519499825384899232==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32

--===============1519499825384899232==--