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

55 篇文章 6 订阅
9 篇文章 0 订阅

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 := ""

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值