2014-10-09 90 views
0

此時,我有一個文檔,您可以從其他程序中輸入多個輸出,根據您在組合框中選擇的人數將這些數據轉換爲一些統計數據和圖形形式控制)。這在此時正常工作。用宏保存word/excel自動生成的文檔

excel連接到MS Word文檔,該文檔顯示Excel文檔中所選人員的圖形和統計信息。

我想要一個按鈕,它可以將具有不同名稱的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 

我已經嘗試了很長時間,但無法管理它,我會非常感激,如果有人可以幫助!

我使用Office 2010

回答

1

要保存文檔爲PDF格式,你只需要運行這行

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

完整的代碼到按鈕薩韋打開一個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