I have a vba script that only update the active dgn file. the script is written to search a few selected files and change the selected text.
I am using microstation v8i. I am new to vba programming so any help will be appreaciated.
the previouse post i have deleted them so only reffer to this post. i have attached the vba script.
thank you guys for your help so far.
Jon can you recommend the best book to acquire to self teach mvba. Thanks again guys.
I can see that your VBA macro successfully populates a ListBox with DGN files.
What exactly doesn't work subsequently?
Regards, Jon Summers LA Solutions
Thank you for replying to my post. After the go button is selected the program should have scan the files in the list box and find and replace the word man to woman. The program only find and replace the word man with woman in the active file.
With comments and unnecessary macro recorder code removed, your GO function boils down to this …
Private Sub btnGo_Click() Dim fileName As String Dim I As Long For I = 1 To lstFilesToProcess.ListCount fileName = lstFilesToProcess.List(I - 1) Debug.Print fileName Next I CadInputQueue.SendCommand "MDL KEYIN FINDREPLACETEXT" ... CadInputQueue.SendCommand "FILEDESIGN" CommandState.StartDefaultCommand End Sub
In a For loop, you trace the contents of your ListBox. Next, after the For loop has finished, you perform a text search-and-change operation.
What you should be doing in your For loop is opening a DGN file for edit …
Private Sub btnGo_Click() Dim I As Long Dim fileName As String Dim oDgnFile As DesignFile For I = 1 To lstFilesToProcess.ListCount fileName = lstFilesToProcess.List(I - 1) Debug.Print fileName Set oDgnFile = OpenDesignFile (fileName) ' Process file's contents ProcessActiveDesignFile Next I CommandState.StartDefaultCommand End Sub
Put whatever you want into method ProcessActiveDesignFile. In your case, put all the text change code …
Function ProcessActiveDesignFile () As Long CadInputQueue.SendCommand "MDL KEYIN FINDREPLACETEXT" CadInputQueue.SendKeyin "FIND DIALOG SEARCHSTRING MAN" CadInputQueue.SendKeyin "FIND DIALOG REPLACESTRING WOMAN" CadInputQueue.SendCommand "CHANGE TEXT ALLFILTERED" CadInputQueue.SendCommand "CHANGE TEXT FIND" CadInputQueue.SendCommand "CHANGE TEXT ALL" CadInputQueue.SendKeyin "task sendtaskchangedasync" CadInputQueue.SendKeyin "task sendtaskchangedasync ""\Drawing""" CadInputQueue.SendCommand "FILEDESIGN" End Function
Answer Verified By: bobby rag
Thanks Jon