VBA/Excel/Access/Word/Word/Word

Материал из VB Эксперт
Перейти к: навигация, поиск

Check the word version

   <source lang="vb">

Sub GetWordVersion()

   Dim WordApp As Object
   Set WordApp = CreateObject("Word.Application")
   MsgBox WordApp.Version
   WordApp.Quit
   Set WordApp = Nothing

End Sub

</source>
   
  


The Word object that"s created is invisible. If you"d like to see the object while it"s being manipulated, set its Visible property to True, as follows:

   <source lang="vb">

Sub GetWordVersion()

   Dim WordApp As Object
   Set WordApp = CreateObject("Word.Application")
   MsgBox WordApp.Version
   WordApp.Visible = True    
   WordApp.Quit
   Set WordApp = Nothing

End Sub

</source>
   
  


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 new document:

   <source lang="vb">

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

</source>