object variable not set error in Word macro intermittant

P

pthomasberkeley

Hello-

I am getting intermittant "error91" messages with this code which operates a
macro to open a 2 separate files, copy all text contents, close and then
paste into the active document.

Sub Macro01040and1050()
ChangeFileOpenDirectory "P:\Spec\"
Documents.Open FileName:="01040.doc", ConfirmConversions:=False,
ReadOnly _
:=False, AddToRecentFiles:=False, Revert:=False, _
Format:=wdOpenFormatAuto
Selection.Copy
ActiveWindow.Close
Selection.Paste
Documents.Open FileName:="01050.doc", ConfirmConversions:=False,
ReadOnly _
:=False, AddToRecentFiles:=False, Revert:=False, _
Format:=wdOpenFormatAuto
Selection.WholeStory
Selection.Copy
ActiveWindow.Close
Selection.Paste
End Sub

I am new to VBA and cannot figure out what is wrong with this code, that
would cause the macro to run most of the time but fail about 20%. Any
thoughts or solutions are appreciated...
 

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