View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Andibevan Andibevan is offline
external usenet poster
 
Posts: 28
Default Open Word Document and Accept Track Changes - Partial Solution

The following function is designed to open a specified word doc and accept
the track changes but I keep getting an 'object variable or with block
variable not set, on the line

Set oDoc = oAppWD.Documents.Open(Filename:=sFilePath)

Any ideas why?

TIA

Andi



Function fAcceptTrackChanges(sFilePath) As Boolean
fAcceptTrackChanges = False
Dim oAppWD As Object
Set oAppWD = OpenWordObj()


Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder

Dim oDoc As Object
Dim r As Long


If Right(sFilePath, 4) = ".doc" Then

Set oDoc = oAppWD.Documents.Open(Filename:=sFilePath)
oDoc.AcceptAllRevisions
oDoc.TrackRevisions = False
oAppWD.Documents.Save
oAppWD.Documents.Close
' Print result
End If

Set oAppWD = Nothing


Set SourceFolder = Nothing

fAcceptTrackChanges = True
End Function


Function OpenWordObj() As Object
Dim m_wrd As Object 'Word.Application

Debug.Print "Open Excel"
On Error Resume Next

Set m_wrd = GetObject(, "Word.Application")
If m_wrd Is Nothing Then
Set m_wrd = CreateObject("Word.Application")
End If

If m_wrd Is Nothing Then
MsgBox "Can't Create Word Object"
'OpenWord = False
Else
'OpenWord = True
End If

DoEvents
' OpenWord = m_wrd

m_wrd.Visible = True
OpenWordObj = m_wrd
End Function