george hart
Board Regular
- Joined
- Dec 4, 2008
- Messages
- 241
The code below was working fine in that it activated my word doc "HSS Fleet Report 0500" - just suddenly stopped working, no error msg though.
It also should copy data from my excel file and paste into the "HSS Fleet Report 0500" word doc but doesn't.
Any ideas would be most appreciated as I'm loosing the will...
Dim WordApp As Object
Dim wrdDoc As Object
Dim tmpDoc As Object
Dim WDoc As String
Dim myDoc As String
myDoc = "HSS Fleet Report 0500"
WDoc = ThisWorkbook.Path & "\" & myDoc & ".doc"
On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
If WordApp Is Nothing Then
' no current word application
Set WordApp = CreateObject("Word.application")
Set wrdDoc = WordApp.Documents.Open(WDoc)
WordApp.Visible = True
Else
' word app running
For Each tmpDoc In WordApp.Documents
If StrComp(tmpDoc.FullName, WDoc, vbTextCompare) = 0 Then
' this is your doc
Set wrdDoc = tmpDoc
Exit For
End If
Next
If wrdDoc Is Nothing Then
' not open
Set wrdDoc = WordApp.Documents.Open(WDoc)
'Excel copy etc
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
WordApp.Activate
ActiveWorkbook:
Selection.PasteSpecial Link:=False, DataType:=20, Placement:=wdInLine, _
DisplayAsIcon:=False
End If
End If
End Sub
HELP please...
It also should copy data from my excel file and paste into the "HSS Fleet Report 0500" word doc but doesn't.
Any ideas would be most appreciated as I'm loosing the will...
Dim WordApp As Object
Dim wrdDoc As Object
Dim tmpDoc As Object
Dim WDoc As String
Dim myDoc As String
myDoc = "HSS Fleet Report 0500"
WDoc = ThisWorkbook.Path & "\" & myDoc & ".doc"
On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
If WordApp Is Nothing Then
' no current word application
Set WordApp = CreateObject("Word.application")
Set wrdDoc = WordApp.Documents.Open(WDoc)
WordApp.Visible = True
Else
' word app running
For Each tmpDoc In WordApp.Documents
If StrComp(tmpDoc.FullName, WDoc, vbTextCompare) = 0 Then
' this is your doc
Set wrdDoc = tmpDoc
Exit For
End If
Next
If wrdDoc Is Nothing Then
' not open
Set wrdDoc = WordApp.Documents.Open(WDoc)
'Excel copy etc
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
WordApp.Activate
ActiveWorkbook:
Selection.PasteSpecial Link:=False, DataType:=20, Placement:=wdInLine, _
DisplayAsIcon:=False
End If
End If
End Sub
HELP please...