runtime error 462

J

Jan

Hello,

I have written a macro in excel where I have a procedure to open a word
document, break the links with excel and close the word document.

The macro in excel is a loop i=1 to 200 of the procedure you see below. For
i=1 everything is going well, but for i=2 I get a runtime error 462 at line
'ActiveDocument.Fields.Unlink'

Is there anyone who can help me?
thanks,
Jan

Sub OpenAndReadWordDoc(i As String)
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
'wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("D:\Survey04\rapport\hoofdstuk
6\Hfdst6 met links.doc")
'ActiveDocument.Fields.Update
ActiveDocument.Fields.Unlink
unlinkexcel
unlinkfooter
With wrdDoc
.SaveAs ("D:\Survey04\rapport\hoofdstuk 6\nederlands\" & i & ".doc")
.Close ' close the document
End With
Set wrdDoc = Nothing
wrdApp.Quit ' close the Word application
Set wrdApp = Nothing
'ActiveWorkbook.Saved = True
End Sub
 

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