Python Forum
Save and Close and Excel sheet with pre defined name
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Save and Close and Excel sheet with pre defined name
#1
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
Reply
#2
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python and pandas: Aggregate lines form Excel sheet Glyxbringer 12 1,692 Oct-31-2023, 10:21 AM
Last Post: Pedroski55
  how to save to multiple locations during save cubangt 1 509 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  Save and Close Excel File avd88 0 2,837 Feb-20-2023, 07:19 PM
Last Post: avd88
  how to read txt file, and write into excel with multiply sheet jacklee26 14 9,497 Jan-21-2023, 06:57 AM
Last Post: jacklee26
  Reading Excel file and use a wildcard in file name and sheet name randolphoralph 6 6,851 Jan-13-2022, 10:20 PM
Last Post: randolphoralph
  Python script for excel sheet Nabil 4 3,217 Jun-01-2021, 05:09 AM
Last Post: Pedroski55
  Add a new column when I extract each sheet in an Excel workbook as a new csv file shantanu97 0 2,190 Mar-24-2021, 04:56 AM
Last Post: shantanu97
  Append excel sheet using openpyxl TammyP 1 2,312 Feb-02-2021, 06:32 PM
Last Post: nilamo
  How to Copy Single Value From One Excel Sheet to Another SunWers 4 4,194 Dec-29-2020, 05:39 PM
Last Post: SunWers
  Writing to existing excel sheet jksvend 0 1,910 Oct-12-2020, 11:19 AM
Last Post: jksvend

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020