Feb-20-2023, 07:19 PM
Hello,
I'm not an expert in regards to coding but I've been coding for a bit and leverage that skillset in my day to day work.
Recently started learning python and currently using it to automate some word and pdf documents that need to be updated several times throughout the year.
I've managed to get all of my code and it is working beautifully. However, because most of the people in my area are not really tech savvy I'm building this tool so it can be controlled through an excel document.
I implemented that change successfully but as I plan on calling the code through a macro from the excel document I need to add code that saves and closes the workbook before the rest of the code starts creating the word and pdf files.
Found save and close modules within the openpyxl library but haven't been able to implement those. Here is the first section of my code where I need to save and close the file:
I'm not an expert in regards to coding but I've been coding for a bit and leverage that skillset in my day to day work.
Recently started learning python and currently using it to automate some word and pdf documents that need to be updated several times throughout the year.
I've managed to get all of my code and it is working beautifully. However, because most of the people in my area are not really tech savvy I'm building this tool so it can be controlled through an excel document.
I implemented that change successfully but as I plan on calling the code through a macro from the excel document I need to add code that saves and closes the workbook before the rest of the code starts creating the word and pdf files.
Found save and close modules within the openpyxl library but haven't been able to implement those. Here is the first section of my code where I need to save and close the file:
import os, sys from docxtpl import DocxTemplate from docx2pdf import convert import openpyxl from openpyxl import Workbook import pandas as pd os.chdir(sys.path[0]) xls = pd.ExcelFile("test.xlsx") wb = Workbook("test.xlsx") #Save and Close the excel file. wb.save() wb.close() #Tried the syntax below and it didn't work either. #Workbook.save(wb) #Workbook.close(wb)I've looked for a solution online but I seem to come across more elaborated examples tailored to specific needs. I just need to figure out the simplest way to save and close the file. Any help or guidance would be appreciated.