View Single Post
 
Old 12-03-2011, 12:53 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Tinfanide,

The line:
Dim AppWord As Word.Application
is only relevant if you've already set a reference to Word.

Try:
Code:
Private Sub CopyToWord()
Dim arr As Variant, x As Long, AppWord As Object
Set AppWord = CreateObject("Word.Application")
arr = Array("A", "B", "C")
With ActiveSheet
  .Cells.Clear
  For x = 1 To 3
    .Range(arr(x - 1) & "1").Value = x
  Next x
  .Range("A1:C1").Copy
End With
With AppWord
  .Visible = True
  .Documents.Add
  With .ActiveDocument
    .Range.Paste
    .Tables(1).Delete
    '.Close SaveChanges:=False
  End With
  '.Quit
End With
Set AppWord = Nothing
End Sub
The two commented-out lines show how to correctly shut down Word without saving. Simply setting AppWord = Nothing doesn't do that - it leaves Word running and, if you re-run the code, another Word instance will be created.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote