Jump to content

Needed: VBA code to change one line of text in 450 files


Recommended Posts

Posted

Needed: VBA source code what would open, search for specifiic text in either MTEXT or DTEXT format and replace it with new text, in 450 files.

 

The text may also reside with in a simple block (not one with attributes) in 200 drawings.

 

I am currently running AutoCAD 2004 on Windows 6.002

Posted
Needed: VBA source code what would open, search for specifiic text in either MTEXT or DTEXT format and replace it with new text, in 450 files.

 

The text may also reside with in a simple block (not one with attributes) in 200 drawings.

Here is not mine, so I don't tested it at all

Give this a try

Option Explicit

'' Requires:
'' AutoCAD/ObjectDBX Common 17.0 Type Library (or 16.0 for A2004-2005)
'' Microsoft Scripting Runtime

'' |||||||||||||||||||||||''
'' |Tested on A2007 only |''
'' |||||||||||||||||||||||''

'' written by LeonidSN 

Dim OldText As String
Dim NewText As String
Dim DirName As String


Sub vMain()

   OldText = InputBox("Enter text for replace:", "Batch Job")
   NewText = InputBox("Enter new text:", "Batch Job")
   DirName = InputBox("Enter full name of folder:", "Batch Job")
   Dim fName As String
   Dim FullName As String

   fName = DirName & "*.dwg"
   fName = Dir(fName)
   FullName = DirName & fName
   Call FileAccess(FullName)

   Do While fName <> ""
       fName = Dir()
       FullName = DirName & fName
       Call FileAccess(FullName)
   Loop

End Sub

Private Sub FileAccess(FullName As String)
   Dim MainDoc As AxDbDocument

   On Error Resume Next
   Set MainDoc = New AXDBLib.AxDbDocument
   MainDoc.Open (FullName)

   Call FileProcessing(MainDoc)

   MainDoc.SaveAs (MainDoc.Name)
   Set MainDoc = Nothing
End Sub

Private Sub FileProcessing(MainDoc As AxDbDocument)
   Dim MS As AcadModelSpace
   Set MS = MainDoc.ModelSpace
   Dim vEntity As AcadEntity
   Dim i As Integer
   Dim entObjectID As Long
   Dim tempObj As AcadObject

On Error Resume Next
For i = 0 To MS.Count
    entObjectID = MS.Item(i).ObjectID
    Set tempObj = MainDoc.ObjectIdToObject(entObjectID)
    If (TypeOf tempObj Is AcadText) Then
       If (tempObj.textString = OldText) Then
           tempObj.textString = NewText
       End If
    End If
Next i

End Sub

 

~J'~

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...