Is this a typo on the email or is your production code really referencing 
filename and fileName?

You need to reference the variable name using the same casing in both places 
(if this is not a typo in your email example).

P.S. I don't think you need the 4 backslashes..  2 usually does the trick, but 
there's nothing from stopping it from working using 4 backslashes.


import win32com.client as w3c



# lowercase

filename = 
'C:\\\\App\\\\Backend\\\\public\\\\MSB_2021\\\\11\\\\SYB_10_7_V1.xlsx'

ExcelApp = w3c.DispatchEx("Excel.Application")
ExcelApp.Visible = False
ExcelApp.DisplayAlerts = False

# mixed case
wb = ExcelApp.Workbooks.Open("{0}".format(fileName))


From: python-win32 <python-win32-bounces+steven=manross....@python.org> On 
Behalf Of Tamara Abugharbieh
Sent: Sunday, December 12, 2021 1:32 AM
To: python-win32@python.org
Subject: [python-win32] pywin can not access excel file

Hi,

We are using winpy32 to automate excel applications using python. The python 
script will be used by users with no administrator privileges, and in this 
case, we are getting the following error:
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft 
Excel', \"Microsoft Excel cannot access the file 
'C:\\\\App\\\\Backend\\\\public\\\\MSB_2021\\\\11\\\\SYB_10_7_V1.xlsx'. There 
are several possible reasons: The file name or path does not exist. The file is 
being used by another program. The workbook you are trying to save has the same 
name as a currently open workbook.\", 'xlmain11.chm', 0, -2146827284)

Things to note:

  1.  The file does exist
  2.  The file is not being used by another program
  3.  The path is correct
  4.  The python script is being successfully used by users with administrative 
privileges

Please find bellow the method I am using to open the excel file:


import win32com.client as w3c



filename = 
'C:\\\\App\\\\Backend\\\\public\\\\MSB_2021\\\\11\\\\SYB_10_7_V1.xlsx'

ExcelApp = w3c.DispatchEx("Excel.Application")
ExcelApp.Visible = False
ExcelApp.DisplayAlerts = False
wb = ExcelApp.Workbooks.Open("{0}".format(fileName))

Appreciate your help.

Best,
Tamara

_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to