import win32com.client
def open_word_document(doc_path):
try:
word_app = win32com.client.Dispatch("Word.Application")
word_app.Visible = False
doc = word_app.Documents.Open(doc_path)
print("Word document opened successfully.")
doc.Close()
word_app.Quit()
except Exception as e:
print("Error:", e)
# 実行例
doc_path = r"C:\path\to\your\document.docx" # ファイルパスを確認
open_word_document(doc_path)
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme