vba如何变vbk—— 微软Word中的ahk应用

vba如何变vbk—— 微软Word中的ahk应用word 另存成 PDF 如果用宏的方式解决 可以录制如下 Sub 宏 1 宏 1 宏 ActiveDocume ExportAsFixe OutputFileNa X AHK office 测试另存成 pdf pdf ExportFormat

大家好,我是讯享网,很高兴认识大家。

word另存成PDF如果用宏的方式解决,可以录制如下:

Sub 宏1() ' ' 宏1 宏 ' ' ActiveDocument.ExportAsFixedFormat OutputFileName:= _ "X:\AHK\office\测试另存成pdf.pdf", ExportFormat:=wdExportFormatPDF, _ OpenAfterExport:=True, OptimizeFor:=wdExportOptimizeForPrint, Range:= _ wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent, _ IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _ wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _ True, UseISO19005_1:=False End Sub

讯享网

不好的地方是每次都需要启用宏才行,如何不用启动宏呢,那据我所知最好的办法就是写ahk脚本,在ahk圈中戏称写vbk。

以上宏vba改写vbk如下:

讯享网oWord:=ComObjActive("Word.Application") oWord.ActiveDocument.ExportAsFixedFormat(OutputFileName:=A_Desktop "\test4.pdf" , ExportFormat:=wdExportFormatPDF , OpenAfterExport:=True , OptimizeFor:=wdExportOptimizeForPrint , Range:= wdExportAllDocument , From:=1 , To:=1 , Item:=wdExportDocumentContent , IncludeDocProps:=True , KeepIRM:=True , CreateBookmarks:=wdExportCreateNoBookmarks , DocStructureTags:=True , BitmapMissingFonts:=True , UseISO19005_1:=False) oWord := ""

方法就是 去掉原来宏中的_连接符将后面内容提上来,并在逗号前面回车 使得每行独立成行,在前面创建oWord := ComObjActive("Word.Application")对象。用该com对象调用相关函数oWord.ActiveDocument.ExportAsFixedFormat


讯享网

并把参数用括号括起来。

做到以上还差关键一步,就是将微软的一些常数声明一下:

wdExportFormatPDF := 17 wdExportOptimizeForPrint := 0 wdExportAllDocument := 0 wdExportDocumentContent := 0 wdExportCreateNoBookmarks := 0 

合起来如下,至于如何加热键那是ahk拿手好戏,这里就不赘述了:

讯享网 wdExportFormatPDF := 17 wdExportOptimizeForPrint := 0 wdExportAllDocument := 0 wdExportDocumentContent := 0 wdExportCreateNoBookmarks := 0 oWord:=ComObjActive("Word.Application") oWord.ActiveDocument.ExportAsFixedFormat(OutputFileName:=A_Desktop "\test4.pdf" , ExportFormat:=wdExportFormatPDF , OpenAfterExport:=True , OptimizeFor:=wdExportOptimizeForPrint , Range:= wdExportAllDocument , From:=1 , To:=1 , Item:=wdExportDocumentContent , IncludeDocProps:=True , KeepIRM:=True , CreateBookmarks:=wdExportCreateNoBookmarks , DocStructureTags:=True , BitmapMissingFonts:=True , UseISO19005_1:=False) oWord := ""

小讯
上一篇 2025-02-23 08:57
下一篇 2025-02-25 21:45

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/50435.html