简体   繁体   English

宏可自动保存Word / Excel生成的文档

[英]Macro to save documents generated with word/excel automatically

At this moment, I have a document where you enter several output from other programs, this data is converted into some statistics and graphs per person depending on who you select in a combobox (form control). 目前,我有一个文档,您在其中输入其他程序的多个输出,此数据将转换为一些统计信息和每人的图表,具体取决于您在组合框(窗体控件)中选择的人。 this works fine at this moment. 此刻此工作正常。

The excel is connected to a MS Word document which displays the graphs and statistics from the person selected in the excel document. excel连接到MS Word文档,该文档显示excel文档中所选人员的图表和统计信息。

I would like to have a button that automatically saves the individual document as PDF with a different name. 我想要一个按钮,该按钮可以自动将单个文档另存为PDF。

manual: open both documents
manual: click on the macro
macro: go to first of the combobox list (this can be done by changing output of combobox to 1)
loop
macro: open word and safe as pdf
macro: if number of people that have to be done is same as output combobox, end
macro: go to the next of the list (change output combobox by +1)
end loop

I have tried it for a long time but cannot manage it, I would be very thankful if somebody could help! 我已经尝试了很长时间,但是无法解决,如果有人可以帮助我,我将非常感激!

I use office 2010 我使用Office 2010

To save a document as PDF you just need to run this line 要将文档另存为PDF,您只需要运行此行

objWordDocument.SaveAs "C:\TEMP\Doc1.pdf", 17

The complete code to a button sabe a opened Word document is below. 下面是一个完整的按钮代码,一个打开的Word文档。

Sub SaveWordAsPDF()
Dim wordObj
Dim objWordDocument As Object
Set wordObj = GetObject(, "Word.Application")
Set objWordDocument = wordObj.Documents(1) '1 is the reference index to the documente, if there are more than 1 opened you need to see wich one is the one you want
objWordDocument.SaveAs "C:\TEMP\Doc1.pdf", 17
End Sub

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

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