Errno 13 Permission denied while running Python Script through VBA

0 votes

Although I have verified using Powershell that my system has the necessary permissions to open it, I am attempting to perform some data analysis on an.xlsm file using a Python script that is opened by VBA.

Interested Python file excerpt:

import pandas as pd
import csv

df = pd.read_excel('2020 csv prices_less_till_thu called from vba1.xlsm')
df.to_csv('2020 csv prices_less_till_thu called from vba1.csv')

filename = '2020 csv prices_less_till_thu called from vba1.csv'

with open(filename) as csv_file:

Knowing that this could be a permissions error (have tried the solution to this), I checked, using the Powershell that the file was not restricted in its access:

Snippet from Powershell

I nonetheless, while running the VBA module:

Set objShell = VBA.CreateObject("Wscript.Shell")
    
    PythonExePath = """C:\Users\[REDACTED]\python.exe """
    PythonScriptPath = """C:\Users\[REDACTED]\Price analysis\Check 2020 from VBA.py"""
    
    objShell.Run PythonExePath & PythonScriptPath

get an Errno13 error:

enter image description here

Mar 30, 2023 in Others by Kithuzzz
• 38,020 points
1,834 views

1 answer to this question.

0 votes

According to the error message, the.xlsm file requested by the Python script cannot be opened because it is being used by another process. This may occur if another application is using the file or if the file is already open in an instance of Excel.

Try closing all instances of Excel and any other programmes that could be utilising the file in order to fix this problem. After that, try rerunning the Python script to see whether the issue persists.

You might try utilising the openpyxl library as an all-in-one library for data analysis on.xlsm files. You may read, write, and execute different data analysis activities on Excel files, including.xlsm files, with this library. Moreover, managing macros and VBA code in Excel files is well supported. Here is an illustration of how to read an.xlsm file using openpyxl:

import openpyxl
import pandas as pd
    wb = openpyxl.load_workbook('file.xlsm', read_only=True, keep_vba=True)
    ws = wb['Sheet1']
    data = []
    for row in ws.iter_rows(values_only=True):
        data.append(row)
    df = pd.DataFrame(data, columns=['Column1', 'Column2', 'Column3'])
    wb.close()
answered Mar 30, 2023 by narikkadan
• 63,720 points

Related Questions In Others

0 votes
0 answers

How to run commands within fabric pods through a batch script?

I am trying to write a batch ...READ MORE

May 30, 2020 in Others by anonymous
• 120 points
954 views
0 votes
0 answers

SSH : Permission denied (publickey,gssapi-with-mic)

I am using centos 5.9. The ssh ...READ MORE

May 6, 2022 in Others by narikkadan
• 63,720 points
1,793 views
0 votes
1 answer

Is there a function to unhide columns in excel through python

Excel file : df.to_excel('demofile.xlsx',index=False) import openpyxl py = openpyxl.load_workbook('demofile.xlsx') exlsheet = ...READ MORE

answered Oct 18, 2022 in Others by narikkadan
• 63,720 points
2,156 views
0 votes
1 answer

How to clear contents of an Excel Workbook through vba

When the range you're referring to doesn't ...READ MORE

answered Nov 19, 2022 in Others by narikkadan
• 63,720 points
779 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,360 views
0 votes
1 answer
0 votes
1 answer

Runtime error 438 while importing data in excel from secured website using VBA

Replace With ieDoc.forms(0) .userType.Value = "1" ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 63,720 points
851 views
0 votes
1 answer

VBA excel - create skype account using powershell script

Although the PowerShell portion has not been ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 63,720 points
632 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP