Integrating With Word - Excel - Outlook - PDF For Office Automation
Integrating With Word - Excel - Outlook - PDF For Office Automation
Cheryl Budaj
Sr. Manager, IT Operations
Takeda Pharmaceuticals International Co.
• http://www.millennium.com
Tips
Top Takeaways
Script
Automation
Multiple apps
State driven
• Query database
Dim rs As New ADODB.Recordset
rs.Open "SELECT COUNT(*) CNT FROM incident", cn
s = "" 'string to build
Do While Not rs.EOF
s = s & rs(0) & vbCrLf 'keep building string
rs.MoveNext
Loop 'iterate over all records
rs.Close
Set rs = Nothing 'clean up
• Simple insert
Selection.Text = s
• Insert HTML
PutHTMLClipboard s 'helper function to put HTML content to clipboard
Selection.PasteSpecial , , , , WdPasteDataType.wdPasteHTML
• Export to PDF
ActiveDocument.ExportAsFixedFormat _
OutputFileName:= strFileName, _
ExportFormat:= wdExportFormatPDF, _
OpenAfterExport:=True, _
OptimizeFor:= wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, _
FROM:=1, To:=1, _
Item:=wdExportDocumentContent, _
IncludeDocProps:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, _
DocStructureTags:=True, _
BitmapMissingFonts:=True
• ODBC driver is from Progress Software; get their manual (some in manual incorrect)
– http://media.datadirect.com/download/docs/openaccess/alloa/sqlref/wwhelp/wwhimpl/js/html/wwhelp.htm
• Use SQL Query tool: Toad Data Point Freeware (renewable 120-day license)
– http://toadworld.com/m/freeware/547.aspx
• VBA code can be stored in document itself or Word application – choose wisely