Change vba code with vba code

Maurizio

Well-known Member
Joined
Oct 15, 2002
Messages
687
Office Version
  1. 2007
Platform
  1. Windows
Hi all,

into "Each vbp In ThisWorkbook.VBProject.VBComponents" how can I, with VBA code, change this code's string:

from:
Public Const CTBOld = "Contab03OLD.xls"
Public Const CTB = "Contab03.xls"

to:
Public Const CTBOld = "Contab04OLD.xls"
Public Const CTB = "Contab04.xls"


For example:

For Each vbp In ThisWorkbook.VBProject.VBComponents
With vbp
With vbp.CodeModule

????????????????????????
?????????????????????????
?????????????????????????

End With
End With
Next vbp

End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

acw

MrExcel MVP
Joined
Feb 13, 2004
Messages
4,814
Hi

Try
Sub aaa()
For i = 1 To Application.VBE.CodePanes.Count
Application.VBE.CodePanes(i).CodeModule.ReplaceLine 1, "public const CTBold = ""contab04old.xls"""
Application.VBE.CodePanes(i).CodeModule.ReplaceLine 2, "public const CTB = ""contab04.xls"""
Next i

End Sub

Tony
 

Maurizio

Well-known Member
Joined
Oct 15, 2002
Messages
687
Office Version
  1. 2007
Platform
  1. Windows
Thanks Tony,
but your solution gine me same problems with xls97' reference.

This runs OK:
'http://xlbysteph.free.fr/aideinformatique/news/vbachangelines.txt

Sub ChangeLineInSubs()

Dim myBook As Workbook
Dim i
Dim j

For Each myBook In Application.Workbooks
For i = 1 To myBook.VBProject.VBComponents.Count
For j = 1 To myBook.VBProject.VBComponents(i).CodeModule.CountOfLines
If myBook.VBProject.VBComponents(i).CodeModule.Lines(j, 1) = "Public Const CTBold = ""Contab03old.xls""" Then
myBook.VBProject.VBComponents(i).CodeModule.DeleteLines j
myBook.VBProject.VBComponents(i).CodeModule.InsertLines j, "public const CTBold = ""Contab04old.xls"""
End If
Next j
Next i
Next myBook
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,096
Messages
5,768,061
Members
425,451
Latest member
JohnBrooksBiddle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top