Python Forum

Full Version: Save and Close and Excel sheet with pre defined name
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I have an automation in progress with following steps and their current status.

Read outlook email (specific to my requirement)<Done>
Download attachment to particular folder as .txt file<Done>
Run a macro built in Excel which will use the downloaded file as input and output in another excel sheet. <Done>
Save the output excel sheet. <Pending>
Attach it to email and send it to list of recipients. <Pending>

For reading email, I am using package win32.client
for excel , i am using openpyxl package.

Help needed for : Saving the excel file generated as output of macro.

Action taken so far:
I have a predefined path to save the workbook but it is not working,
I have tried making the output file visible - True and False both.When True, it pop up the file but didnt save.When False, it pops up the save as file name same as input file which is .txt file.The requirement is to save it as excel format file.

Any advice will be thankful
(Nov-28-2018, 04:38 AM)Vinci141 Wrote: [ -> ]Hello,

I have an automation in progress with following steps and their current status.

Read outlook email (specific to my requirement)<Done>
Download attachment to particular folder as .txt file<Done>
Run a macro built in Excel which will use the downloaded file as input and output in another excel sheet. <Done>
Save the output excel sheet. <Pending>
Attach it to email and send it to list of recipients. <Pending>

For reading email, I am using package win32.client
for excel , i am using openpyxl package.

Help needed for : Saving the excel file generated as output of macro.

Action taken so far:
I have a predefined path to save the workbook but it is not working,
I have tried making the output file visible - True and False both.When True, it pop up the file but didnt save.When False, it pops up the save as file name same as input file which is .txt file.The requirement is to save it as excel format file.

Any advice will be thankful
def runMacro():
    if os.path.exists( r"path_to_macro_excel_file" ):
        xl = win32com.client.Dispatch( "Excel.Application" )
        print( "Opening Macro File now." )
        time.sleep(2)
        xl.Workbooks.Open( os.path.abspath( r"path_to_macro_excel_file" ) )
        print( "Running Macro now..." )
        xl.Application.Run( "Macro_name" )
        x1.Visible= True
     
        xl.Workbooks.Save( r"Output.xls" )
        print( "File Saved. Exiting now." )
        xl.Application.close()
        xl.Application.Quit()
        del xl