简体   繁体   中英

Word = win32.Dispatch("Word.Application") Displays the opened file every other time despite Word.Visible = False command

I am having a terrible time getting win32com.client to cooperate. It seemingly switches application state to "visible" and ignores my Visible = False commands. I think this is an error in the package, but I want to see if anybody on here has any ideas first. The bug is more annoying than anything, it causes the file referenced in my path variable to be open every other time.

The code below should opens an instance of MS Word in the background , then accesses the referenced file.

It currently opens a word application every other time the code is run. Ideas...?

import win32com.client as win32

path = 'string to my file'

Word = win32.Dispatch("Word.Application")
Word.Visible = False
Word.Documents.Open(path)

Try

word = win32.Dispatch("Word.Application")
word.Visible = True
word.Documents.Open(docPath)
doc = word.ActiveDocument

Only difference I see is an uppercase W in 'word.Visible' in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM