I am trying to run a particular function, I tested this yesterday and it works. I wanted this looped but when excel tries the same function for the next row, I get a file path error.
Any ideas? Any help would be much appreciated.
Option Explicit
Sub odoc()
Dim fpath As String
Dim objWord As Object
Dim cel As Range
Dim selectedRange As Range
Set objWord = CreateObject("Word.Application")
fpath = Application.ActiveCell.Value
Set selectedRange = Application.Selection
For Each cel In selectedRange.Cells
objWord.Documents.Open (fpath)
objWord.Visible = True
objWord.Application.Run MacroName:="CopySAM"
ActiveCell.Offset(0, 14).Select
ActiveSheet.Paste
objWord.Application.Quit
ActiveCell.Offset(1, -14).Select
Next cel
End Sub
Thanks.
fpathis set outside the loop and so never changes?objWord.Documents.Open(cel.value)in your loop. Right now, it looks like it's opening the same word document over and over.objWord.Application.Quit. The next time the loop comes around, Word is no longer open.