如何解决如何使用 python 调用方法 ChangeFileOpenDirectory (VBA)
我正在尝试将代码从 VBA 映射到 python。一切看起来都很完美,但是当我使用 ChangeFileOpenDirectory 方法时遇到了问题,我真的不知道在哪里调用这个函数。
这是我的代码: 蟒蛇:
import pprint
import win32com.client as win32
word = win32.gencache.EnsureDispatch("Word.Application")
wdExportFormatPDF = 17
wdExportOptimizeForPrint = 0
wdExportAllDocument = 0
wdExportDocumentContent = 0
wdExportCreateHeadingBookmarks = 1
word.Visible = True
doc = word.Documents.Open("E:/PYTHON_COMPUTER_VISSION/FINAL_PROJECT/ICO/BAO_CAO.docx")
doc.Active()
word.ActiveDocument.TrackRevisions = False
word.ActiveDocument.Revisions.AcceptAll()
# Delete all comments
if word.ActiveDocument.Comments.Count >= 1:
word.ActiveDocument.DeleteAllComments()
word.ActiveDocument.Save()
word.ActiveDocument.ExportAsFixedFormat(OutputFileName = "C:/Users/PC/Desktop/Test.pdf",ExportFormat=wdExportFormatPDF,OpenAfterExport=True,OptimizeFor = wdExportOptimizeForPrint,Range = wdExportAllDocument,From = 1,To = 1,Itemn = wdExportDocumentContent,IncludeDocProps = True,KeepIRM = True,CreateBookmarks = wdExportCreateHeadingBookmarks,DocStructureTags = True,BitmapMissingFonts = True,UseISO19005_1 = False)
doc.Close(False)
word.Application.Quit()
VBA:
Attribute VB_Name = "NewMacros"
Sub TurnOffMarkup()
Attribute TurnOffMarkup.VB_ProcData.VB_Invoke_Func = "Normal.NewMacros.TurnOffMarkup"
'
' TurnOffMarkup Macro
'
'
With ActiveWindow.View.RevisionsFilter
.Markup = wdRevisionsMarkupNone
.View = wdRevisionsViewFinal
End With
ActiveDocument.AcceptAllRevisions
ActiveDocument.Save
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"C:\Users\PC\Desktop\BAO_CAO.pdf",ExportFormat:=wdExportFormatPDF,_
OpenAfterExport:=True,OptimizeFor:=wdExportOptimizeForPrint,Range:= _
wdExportAllDocument,From:=1,To:=1,Item:=wdExportDocumentContent,_
IncludeDocProps:=True,KeepIRM:=True,CreateBookmarks:= _
wdExportCreateHeadingBookmarks,DocStructureTags:=True,_
BitmapMissingFonts:=True,UseISO19005_1:=False
**ChangeFileOpenDirectory "C:\Users\PC\Desktop\"**
ActiveWindow.Close
Application.Quit
End Sub
遇到过这个问题的人请给我建议。非常感谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。