Mega Code Archive

 
Categories / VisualBasic Script / Word
 

Uses errors to learn whether Word is already open before pasting a chart at the end of a document If not, it opens Word and creates a

Sub IsWordOpen()     Dim wdApp As Word.Application     ActiveChart.ChartArea.Copy     On Error Resume Next     Set wdApp = GetObject(, "Word.Application")     If wdApp Is Nothing Then         Set wdApp = GetObject("", "Word.Application")         With wdApp             .Documents.Add             .Visible = True         End With     End If     On Error GoTo 0          With wdApp.Selection         .EndKey Unit:=wdStory         .TypeParagraph         .PasteSpecial Link:=False, DataType:=wdPasteOLEObject, _             Placement:=wdInLine, DisplayAsIcon:=False     End With          Set wdApp = Nothing End Sub