Open Word Document and Accept Track Changes - Partial Solution

A

Andibevan

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
 
J

JingleRock

I am having a problem with a similar stmt (my query on this forum is
slightly older -- 1 NOV 7:09AM; the Subject is ==> Running Macro
"Logged Off" & Copy/Paste from WORD .rtf into EXCEL .xls

Two changes in my posted code: my file open stmt is now
'Set objDoc = objWord.Documents.Open ("C:\Test\T and A.rtf")';
and I deleted the next stmt 'objDoc.Activate'.

When my machine is "logged on", my code works as intended. However,
when "logged off" our network, my code stops processing at my revised
'Set objDoc = ...' stmt. And I have about 100 lines of EXCEL VBA code
that is processed before it reaches that point.

Any ideas?
JingleRock
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top