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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,962
Latest member
Fenes

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
Back
Top