2017-08-28 14 views
0

我正在使用Excel,PowerPoint和Word OLE對象,我的目標是'悄然地'將文檔轉換爲PDF。如何以編程方式打開一個新的'隱藏的'PowerPoint/Word/Excel窗口進行處理

目前,我有以下的非沉默方法:

Class PowerPointExporter 
    Sub Export(path As String, newPath As String) 
     Dim application As New PowerPoint.Application 
     Dim presentation As PowerPoint.Presentation = application.Presentations.Open(path) 
     presentation.SaveAs(newPath, PowerPoint.PpSaveAsFileType.ppSaveAsPDF) 
     presentation.Close() 
     application.Quit() 
    End Sub 
End Class 
Class ExcelExporter 
    Sub Export(path As String, newPath As String) 
     Dim application As New Excel.Application 
     Dim wb As Excel.Workbook = application.Workbooks.Open(path) 
     wb.SaveAs(newPath, Excel.XlFixedFormatType.xlTypePDF) 
     wb.Close() 
     application.Quit() 
    End Sub 
End Class 
Class WordExporter 
    Sub Export(path As String, newPath As String) 
     Dim application As New Word.Application 
     Dim doc As Word.Document = application.Documents.Open(path) 
     doc.SaveAs2(newPath, Word.WdSaveFormat.wdFormatPDF) 
     doc.Close() 
     application.Quit() 
    End Sub 
End Class 

所以我的問題是,如何才能讓這些沉默? I.E.隱藏窗口/將窗口移出屏幕,或類似的?

回答

2

對於PowerPoint:

Set PPTObj = New PowerPoint.Application 
    If Debugging Then 
    Set PPTClinic = PPTObj.Presentations.Open(fileName:=PPTFileName, ReadOnly:=msoCTrue, WithWindow:=msoTrue) 'this will prevent the window from being visible 
    Else 
    Set PPTClinic = PPTObj.Presentations.Open(fileName:=PPTFileName, ReadOnly:=msoCTrue, WithWindow:=msoFalse) 'this will prevent the window from being visible 
    End If 

注意最後的WithWindow參數。

對於Excel:

Set XLobj = New Excel.Application 
    If Debugging Then 
    XLobj.Visible = True 
    Else 
    XLobj.Visible = False 
    End If 

我沒有在Word中做任何事了相當多的時間,但它可能是類似的東西。我看看谷歌說...

啊,here它是字:

Application.Visible = False 

對不起,沒有漂亮的例子颳起了 - 我把前兩個從我現有的代碼,最後一個剛剛從鏈接頁面借用。

相關問題