ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   modifying code using addfromfile method (https://www.excelbanter.com/excel-programming/325748-modifying-code-using-addfromfile-method.html)

PaulR

modifying code using addfromfile method
 
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?

Bob Phillips[_6_]

modifying code using addfromfile method
 
Paul,

As ever, your code would help.

--

HTH

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


"PaulR" wrote in message
om...
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?




[email protected]

modifying code using addfromfile method
 
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").V BComponents
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.



All times are GMT +1. The time now is 12:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com