简体   繁体   English

Word = win32.Dispatch("Word.Application") 尽管有 Word.Visible = False 命令,但每隔一次显示打开的文件

[英]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.我很难让 win32com.client 合作。 It seemingly switches application state to "visible" and ignores my Visible = False commands.它似乎将应用程序状态切换为“可见”并忽略我的 Visible = False 命令。 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.下面的代码应该在后台打开一个 MS Word 实例,然后访问引用的文件。

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.我看到的唯一区别是代码中“word.Visible”中的大写 W。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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