modifying code using addfromfile method

P

PaulR

I am writing a macro which corrects code in many standard workbooks. I
have a loop which deletes all the code from a module and then adds the
corrected code from a file using the addfromfile method. The loop
works correctly with the first workbook but not any subsequent
workbooks. Why does the addfromfile method only work once?
 
B

Bob Phillips

Paul,

As ever, your code would help.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
P

preedy

This is the routine which swaps the code:

Sub MSmodMender() 'replaces code in a module with code from a text file
For Each i In
Application.VBE.VBProjects("VBAMidasWrkShtProj").VBComponents
If i.codemodule.Name = "UpdatePhaseMod" Then 'need to name the
module to be replaced
i.codemodule.DeleteLines 1, i.codemodule.CountOfLines 'delete
all lines in the module
i.codemodule.AddFromFile "cape cod:fmidas:closet:back
shelf:UpdatePhases03042005.txt" 'need to name the text file
Exit Sub
End If
Next
End Sub

It works fine on the first workbook I loop to, but on all subsequent
loops only the DeleteLines method statement works. The statement with
AddfromFile method does nothing, not even an error.

Thanks for any help you can offer.
 

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