Python Forum

Full Version: python coding to run file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Please help in the python command.

file location is below which has to be open and run command than save.
‪I:\new\ACR\FINAL AUTO ACER.xlsx

I want the python command to open the above file than press (ALT+F5) which is refress command
than wait for 15 seconds then save the same file and close.

thanks in advance.
import time
import pyautogui
import os

# Specify the file path
file_path = r"I:\new\ACR\FINAL AUTO ACER.xlsx"

# Open the file
os.startfile(file_path)

# Wait for the file to open
time.sleep(2)  # Adjust this delay as needed

# Send ALT + F5 key to refresh
pyautogui.hotkey('alt', 'f5')

# Wait for 15 seconds
time.sleep(15)

# Save the file
pyautogui.hotkey('ctrl', 's')

# Wait briefly
time.sleep(2)

# Close the file (assuming it's already saved)
pyautogui.hotkey('alt', 'f4')
Make sure you have installed pyautogui (pip install pyautogui) before running this script. Adjust the timings (time.sleep) as necessary based on your system's responsiveness.