LEARNing Conference Product Communities Bentley and User Communities User Blogs and Files About This Site BE COMMUNITIES HELP DETAILS OPTIONS Home Product Communities MicroStation MicroStation Programming [Archived] MicroStation V8 XM Edition Programming Forum Controlling Microstation from Excel VBA MicroStation Programming This community is where you can find and contribute to discussions, ideas, and other information about developing with any MicroStation SDK and MicroStation VBA. Get this RSS feed Home Blogs Forums Files Wikis Getting Started Common Acronyms FAQ Forum Help Forum Tips FTP Site Helpful Guidelines Inserting and Attaching images, videos, or files to posts Product Community Directory SELECTsupport 27 Replies 2 Subscribers 1573 days old Subscribe via RSS Send to friend [ARCHIVED] MICROSTATION V8 XM EDITION PROGRAMMING FORUM Controlling Microstation from Excel VBA Posted by Shegde on Mon, Apr 19 2010 7:15 PM Hi Rabi,
Yes. I have changed the type of the Model to sheet only to those model which consists of Tag. Each drawing has only one sheet type model. But still it doesn't work. I really appreciate if you could let me know how to tweak VBA to check all models and update the Tags where ever it finds them. Thanks, Shubha. Posted by Rabi on Mon, Apr 19 2010 1:33 PM Yes you can do that. When you say, "changing the type of the Model to Sheet " you are changing only the model which has tags in it right? The reason I suggested you change it to sheet type is to distinguish that one particular model which contains all your tags. If you have two sheet models then the last one in your model list is considered. I hope this helps. Sincerely, Rabi Join Sign in Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] Posted by Shegde on Thu, Apr 15 2010 7:31 PM Hi Rabi, Thanks again. I tried the VBA after changing the type of the Model to Sheet as per your suggestion but, it still fails. VBA doesn't do anything as before. Where as I tried VBA on our other decipline drawings where they have only one default model, it works perfectly even though none of the models are sheet type. It seems like this VBA doesn't work on those drwaing which contains multiple model. Is there a way to tweak the macro to check all models and update the Tags which ever model it finds the Tags in without checking for the type of the model? Thanks for the help. Shubha. Posted by Rabi on Tue, Apr 13 2010 10:11 PM Hello Shubha, I am glad to know that the system works for cells as well. Thank you for the information. I think I know the problem you are facing. The DGN that is not working have various models in it. The EXCEL macro looks to one of these models and not all models for tags. Thus unfortunately the model this macro is looking for doesn't have any tags in them. For automation purposes consistency is somewhat very important. In your case there are several models in the DGN file. To solve the issue you can change the model type to sheet in which your tags are stored. Then the variable "msdModelTypeSheet" becomes active and the macro finds tags accordingly. You can change the model type to sheet from Models dialog box (its the blue icon). Typically the models are "msdModelTypeNormal". Also there is a distinction between a default model which is "msdModelTypeDefault". This means you can also choose default model for your tags. And in code we can instruct the macro to look into default model and not any other models. I recommend you use Sheet model type and only one sheet model type for each DGN file used for sheets. That makes lots of things easier down the line. The EXCEL macro has an error which uses a undefined variable "msdModelTypeModel". The VBA reference I have used for XM edition there is no such type of variable defined. If you do a quick search for "msdModelTypeModel" and replace it with "msdModelTypeNormal" the program will function as designed. I wrote the VBA for the purpose of our workflow. We have sheet model setup for all our tags. Thus the macro searches for sheet model type and finds the tags. In your case there are no defined models which have tags in them. This is the prime reason some dgn are working while the others are not. If you open the ones which are working they should only have one model i.e. Default model. In conclusion I recommend you to find a consistent method of putting tags. That could be in sheet model type (given only one sheet type exists) or name your model with some constant so that you can refer to the model with tags by its name. Or just put all tags in the default model and tweak the macro to look only into the models. I hope this helps you. Let me know what happens. If you determine a workflow or a consistent model organization let me know and I shall help you with getting the codes tuned for you. Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] Sincerely, Rabi Posted by Shegde on Tue, Apr 13 2010 7:53 PM
P100_320_Abut_Detail.dgn Hi Rabi, Thanks for suggestions. Even though I use cell to place the Tags, these tags are live in the drawing and can be edited just like regular Tags. I have 31 dgn files and spread sheet works only on 2 drawings. I'm able to import and export to these 2 drawings. One good news is VBA works on cell as well. I have attached the Tags through cell to all my 31 drawings. It works on 2 drawings. Another thing is, somehow I fixed the error messge adding "On Error Resume Next' code right before where it encounters the error. I'm not sure if that is the right way or not. But it works for now. Now only problem I have is why it doesn't work on rest of the drawings. I'm attaching 2 dgn files for review, one where VBA works and the other where VBA doesn't do anything. 1. P100_320_General_Notes.dgn (Excel VBA works on this file) 2. P100_320_Abut_Detail.dgn (Excel VBA doesn't work on this file) Any help would be greatly appreciated. Thanks, Shubha. Posted by Rabi on Wed, Apr 7 2010 10:19 PM
tagsEdited.PNG From what I understood is she is trying to insert CELLS in the drawing sheet as opposed to graphic grouped tags. Now that she has inserted the CELLS she is locking the tags in the cell header which this excel won't do any good. My suggestion is to put the tags in the title block as a placeholder. Whenever you attach the title block you can copy these tags (graphic grouped) to match a predefined insert points. Then double clicking the tags will open it for editing. These tags are now directly in the sheets and thus will be imported successfully. The export will then work as well. I hope this helps. Please refer to the attached picture for the concept we use in our office. The tags in the right are in the referenced title block. The tags on the left are copied tags in the drawings. Each tag is editable and free for VBA edit (I mean not in a cell). Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] Thanks, Rabi Posted by Jon Summers on Wed, Apr 7 2010 9:50 PM Sharing Error Information Shubha: It also gives me error while exporting the same. (Run-time error '-2147218396 (80040c24)': File is read-only). We used to debug code telepathically, but there's too much interference from the ozone layer these days. We can't see your code, so we don't know where you encountered that error. Why not step through in debug (Function key F8) to find where your code fails. Then post some of that code here with more information about the failure. If the code is attempting to open a file, does that file really exist? Is it opening the code for write access? Regards, J on Summers LA Solutions Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] Posted by Rabi on Wed, Apr 7 2010 9:48 PM Hi Shubha, My knowledge of VBA for CELLS is limited. I am not sure how you can modify (if you could) CELLS with VBA. If you were able to import information from the dgn that you had tagset created then the process is working. For this VBA to work Tags need to be on thier own and not a part of the CELL. Also if you are considering CEL as one file then perhaps you could change the file type to CEL and it might work. Is it not possible for you to put tags directly in the drawings? I mean you can create tags in Title reference and copy them into your sheets for changing values. Let us know what your process is. Sincerely, Rabi Posted by Shegde on Wed, Apr 7 2010 7:54 PM
Drawing Tags Import -Export.xls Hi Rabi, I'm sorry to say that it just doesn't work for me. Spread Sheet imports the tag values from only one file where I actually created Tag set. Rest of the dgn files where I attached the tag thorugh cell (I have created a cell contating tag) , spread sheet does'nt import any Tag information. It also gives me error while exporting the same. (Run-time error '-2147218396 (80040c24)': File is read-only). I have attached the cell which contains the Tag set as well as the spread sheet I'm using. Any help would be really appreciated.
Thanks, Shubha.
Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] Posted by Rabi on Fri, Mar 26 2010 9:04 PM Hi Shubha, The process works like this. You import the tag information from your drawings. Once imported you can modify them as you need and then export the edited information back to the drawings. If you maximize the downloaded sheet, you should see a page with "How to use." It gives some basic idea about the process. The column headings such as "J ob No.", "Drawing No.", "Sheet Description 1" are the tag names. There is a cell where you put the Tagset Name (Case Sensitive and one word). Fill those information and match your tag names into the columns. You can get those information from MicroStation. Once you modify your Excel sheet import the tag information then you should have the file names column populated. You must select these cells that have the file names you want to update. Say you imported and edited only one file. Then select the file name cell and hit export. This will only export information to the selected file name in Excel. Let me know if that helped. Sincerely, Rabi Posted by Shegde on Fri, Mar 26 2010 8:08 PM
Hi Rabi, I was searcing for the VB program which takes the data from Excel Spredsheet and updates microstation title and drawings numbers and I came across the program you wrote. I copied the program and drawing Tags Import- Export.xls. When I ran the program I got a error message saying : "Selection is not a valid DGN path. Please select range with valid DGN filenames". Since I don't know anything about the programming and there is not much information about how to use this progam along with the above spread sheet, I don't know what to do. I really appreciate if you could guide me. Thanks, Posted by Rabi on Mon, Nov 23 2009 7:12 PM Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] Hi J on, Yes I am very happy to get a program made and we are using it for managing out title block information. This EXCEL VBA imports the tag information and we can edit them in Excel and later push it back to DGN in matter of minutes. Basically the codes are the same as illustrated here below in this thread. I appreciate your help regarding issues I was having earlier. Sincerely, Rabi Posted by Jon Summers on Mon, Nov 23 2009 6:24 PM Rabi: I am just trying to read information from the tags at this point. Have you made progress with this? Your comments in another thread (Nov 09) suggest that you have got somewhere ... In answer to your question: reading tag data does not modify anything in your DGN model. You can get tag data from a read-only model, including reference attachments. Regards, J on Summers LA Solutions VBA, programming Posted by Rabi on Wed, Mar 25 2009 3:59 PM Jon Summers: [The sample code you posted attempts to modify tag elements. Are those tag elements created by one of Bentley's building applications? J on, I am just trying to read information from the tags at this point. So I am not sure if my macro attempts to modify the tag elements. I am not sure how this process actually works inside microstation. I have the file opened as read only at this time. Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] VBA, programming Posted by Rabi on Wed, Mar 25 2009 3:41 PM The tags I am trying to modify is custom created. The tags are used in our Title Block to manage TB information. Furthermore, the error message I got is related to msdTagSetNotFound error. Why would Microstation report Tag Set Not Found when there is this tag I inserted into the drawing? VBA, programming Posted by Rabi on Wed, Mar 25 2009 3:39 PM Dear J on, Thank you for pointing the commented 'OnError Handler" I think I have resolved the error handling part atleast. Still need to look into the file which generates this error when I have all the tagsets in the drawing. Any thoughts on why the error is thrown? Posted by Jon Summers on Wed, Mar 25 2009 3:31 PM Rabi: This is more accurate error message I get when I opened the drawing in microstation. "Change rejected in order to preserve design integrity." Message Details: "The originating application (48770) rejected this change in order to preserve the element's design integrity." Do you know what application is (48770) ? That's not, as Phil reveals, a VBA message. It occurs when you, or your code, tries to modify an element marked as 'not for modification' by another application. The sample code you posted attempts to modify tag elements. Are those tag elements created by one of Bentley's building applications? Regards, J on Summers LA Solutions Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] Posted by Phil Chouinard - Bentley on Wed, Mar 25 2009 3:17 PM That would be one of our Building applications and is intentional to avoid making modifications to any element (placed with that application) without that application being present. VBA, programming Posted by Rabi on Wed, Mar 25 2009 3:07 PM Oh sorry! I was going to remove that line but I didn't. Its not a part of the code. I added it later just before I posted the code here and I completely forgot about it. My appologies. This is more accurate error message I get when I opened the drawing in microstation. "Change rejected in order to preserve design integrity." Message Details: "The originating application (48770) rejected this change in order to preserve the element's design integrity."
Do you know what application is (48770) ?
Posted by Jon Summers on Wed, Mar 25 2009 2:12 PM Rabi: 'On Error GoTo ErrHandler if myDGN.Models(1).HasAnyXData Something's not right here: 1. Your On Error statement is commented out 2. if myDGN.Models(1).HasAnyXData is incorrect -- it should have a Then clause Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] Regards, J on Summers LA Solutions Posted by Rabi on Wed, Mar 25 2009 1:55 PM Hi J on, Here below please find the codes I am using for one of the procedures. I get the following message. "System Error &H8004057A (-2147220102)" . I get this error in two situation. One when the tagSets are not found in the drawing file. And the second when the drawing file is intentionally restricted by microstation for modification. When I opened this individual dgn drawing file in microstation, microstation reported that it was intentionally restricted for modification.
Sub ImportTitleBlockTags() Dim askUser As Integer askUser = MsgBox("This process will replace the current information in your Excel Sheet! Do you want to continue?", vbYesNo, "Confirmation") If askUser = 7 Then MsgBox ("You chose to exit the import process.") Exit Sub End If 'Microstation Related Variables Dim myDGN As DesignFile Dim myTagSet As TagSet Dim myTag As TagElement Dim myEleEnum As ElementEnumerator Dim myEleFilter As New ElementScanCriteria Dim myString As String 'Microstation Application Dim myUstation As MicroStationDGN.Application 'File System Related Variables Dim myFSO As New Scripting.FileSystemObject Dim myFolder As Scripting.Folder Dim myFile As Scripting.File 'Excel Related Variables Dim myWS As Excel.Worksheet Set myWS = Excel.ThisWorkbook.ActiveSheet Dim CurRow As Long 'Dim myNumber As Integer 'Application.ScreenUpdating = False 'Faster code execution 'On Error GoTo ErrHandler ErrHandler: Select Case Err.Number Case 5 MsgBox "The Cells(3,3) or 'C3' should have valid path to the folder containing sheet files." Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] Exit Sub Case -2147220102 MsgBox "MicroStation reported that tagset was not found! & vbCrLf & Check if the tagset STD_TITL exists in the drawing file." Exit Sub Case -2147220093 MsgBox "MicroStation reported that tag was not found!" & vbCrLf & "Make sure the tags exists in the drawing file." Exit Sub Case -2147220101 MsgBox "MicroStation reported that tag was not found in the tag set!" & vbCrLf & "Make sure the tag is defined in the tag set." Exit Sub End Select 'Current Row can be set according to the Template CurRow = 5 'myNumber = 1 'Get files from the folder Set myFolder = myFSO.GetFolder(myWS.Cells(3, 3)) 'Get Microstation for file processing Set myUstation = New MicroStationDGN.Application 'Loop through each file For Each myFile In myFolder.Files Select Case myFile.Type Case "Bentley MicroStation Design" 'Open Microstation Files for programming Set myDGN = myUstation.OpenDesignFileForProgram(myFile.Path, True) 'Write File Name myWS.Cells(CurRow, 2) = myDGN.Name 'myEleFilter.Reset myEleFilter.ExcludeAllTypes 'myEleFilter.ExcludeGraphical myEleFilter.IncludeType msdElementTypeTag Set myEleEnum = myDGN.Models(1).Scan(myEleFilter) if myDGN.Models(1).HasAnyXData 'Holder for Title Tag Array Dim myTitle(3) Dim myTitleString As String 'Clear myTitle Array Dim x As Integer For x = 0 To 3 myTitle(x) = "" Next myTitleString = "" 'Clear to begin with 'Loop within the Enum While myEleEnum.MoveNext Set myTag = myEleEnum.Current myString = myTag.TagSetName 'Check the name for Tagset If myString = "STD-TITL" Then Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] 'Sheet Title Holder 'Check if its Hidden If myTag.IsHidden = False Then 'Sheet No Tag If myTag.TagDefinitionName = "SHT_NO" Then myWS.Cells(CurRow, 3) = myTag.Value End If 'Sheet Title Tag If myTag.TagDefinitionName = "SHT_TITLE1" Then myTitle(0) = myTag.Value End If If myTag.TagDefinitionName = "SHT_TITLE2" Then myTitle(1) = myTag.Value 'MsgBox myTitle(1) End If If myTag.TagDefinitionName = "SHT_TITLE3" Then myTitle(2) = myTag.Value End If If myTag.TagDefinitionName = "SHT_TITLE4" Then myTitle(3) = myTag.Value End If 'Strip spaces from the titles myTitleString = myTitle(0) & " " & myTitle(1) & " " & myTitle(2) & " " & myTitle(3) myTitleString = LTrim(myTitleString) 'Left striping myTitleString = RTrim(myTitleString) 'Right Striping myWS.Cells(CurRow, 4) = myTitleString 'Drawn By Tag If myTag.TagDefinitionName = "DRAWNBY" Then myWS.Cells(CurRow, 5) = myTag.Value End If 'Checked By Tag If myTag.TagDefinitionName = "CHECKEDBY" Then myWS.Cells(CurRow, 6) = myTag.Value End If 'Approved By Tag If myTag.TagDefinitionName = "APPROVEDBY" Then myWS.Cells(CurRow, 7) = myTag.Value End If 'Date Tag If myTag.TagDefinitionName = "TDATE" Then myWS.Cells(2, 6) = myTag.Value End If 'Project No. Tag If myTag.TagDefinitionName = "PROJ_NO" Then myWS.Cells(2, 3) = myTag.Value End If 'Total sheet Tag If myTag.TagDefinitionName = "TOTAL_NO#" Then myWS.Cells(1, 6) = myTag.Value End If 'Sheet no. for of total If myTag.TagDefinitionName = "SEQ_NO#" Then myWS.Cells(CurRow, 1) = myTag.Value Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] VBA, programming End If 'Check if the revisions are present Dim iRevCounter As Integer For iRevCounter = 1 To 9 If myTag.TagDefinitionName = "REV" & iRevCounter Then If myTag.Value <> "" Then myWS.Cells(CurRow, 10) = "YES !" End If End If If myTag.TagDefinitionName = "DATE" & iRevCounter Then If myTag.Value <> "" Then myWS.Cells(CurRow, 10) = "YES !" End If End If If myTag.TagDefinitionName = "BY" & iRevCounter Then If myTag.Value <> "" Then myWS.Cells(CurRow, 10) = "YES !" End If End If If myTag.TagDefinitionName = "DESCRIPT" & iRevCounter Then If myTag.Value <> "" Then myWS.Cells(CurRow, 10) = "YES !" End If End If Next End If End If myWS.Cells(CurRow, 9) = "" 'Erase the export flags Wend 'Set myTagSet = myDGN.TagSets("STD-TITL") 'Write Number 'myWS.Cells(CurRow, 1) = myNumber 'Close Microstation myDGN.Close myWS.Cells(CurRow, 8) = "SUCCESS !" 'Update the increments 'myNumber = myNumber + 1 CurRow = CurRow + 1 End Select Next 'Release variables MsgBox "The Title Block Tags were successfully imported." End Sub Posted by Jon Summers on Wed, Mar 25 2009 8:53 AM Rabi: I ran into problems when MicroStation reports some error. Do you know of a way where you can trap that error from within EXCEL VBA? I tried the runtime error catch method but didn't work. Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] On Error GoTo ErrHandler Please post the complete subroutine where you use the On Error ... statement. Regards, J on Summers LA Solutions VBA, programming Posted by Rabi on Tue, Mar 24 2009 9:13 PM Dear J on, I am far ahead in my work regarding managing tag information from within EXCEL spreadsheet. I ran into problems when MicroStation reports some error. Do you know of a way where you can trap that error from within EXCEL VBA? I tried the runtime error catch method but didn't work. On Error GoTo ErrHandler ErrHandler: Select Case Err.Number Case 5 MsgBox "The Cells(3,3) or 'C3' should have valid path to the folder containing sheet files." Exit Sub Case -2147220102 MsgBox "MicroStation reported that tagset was not found! & vbCrLf & Check if the tagset STD_TITL exists in the drawing file." Exit Sub Case -2147220093 MsgBox "MicroStation reported that tag was not found!" & vbCrLf & "Make sure the tags exists in the drawing file." Exit Sub Case -2147220101 MsgBox "MicroStation reported that tag was not found in the tag set!" & vbCrLf & "Make sure the tag is defined in the tag set." Exit Sub End Select
Any suggestions how I can actually use these Err.Numbers to handle them from EXCEL VBA?
Sincerely, Rabi Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] VBA, scanning Posted by Jon Summers on Wed, Feb 11 2009 6:29 PM ModelReference.Scan Rabi: How do I populate oHost with elements if I need to process tags in a file or multiple files as such. In MicroStation, elements reside in a model (VBA ModelReference). There is always one model in a DGN file. There may be multiple models in a DGN file. One model may be attached to another as a reference. You can only add or modify elements in the active model (VBA ActiveModelReference). The idiom for getting elements from a model is scan. Every model has a Scan method. There are some hints on model scanning. Regards, J on Summers LA Solutions Posted by Rabi on Tue, Feb 10 2009 11:16 PM Hi J on, I wanted to ask if this code would be a valid code. How do I populate oHost with elements if I need to process tags in a file or multiple files as such. You suggestion would help me a lot. Should I use enumeration? Dim oHost As Element ... ' Read oHost element from file If (oHost. HasAnyTags) Then Dim oTags() As TagElement Dim nTags As Integer Dim i As Integer Dim vtValue As Variant oTags = oHost.GetTags () ' process tag array For i = Lbound (oTags) To Ubound (oTags) vtValue = oTags(i).Value Debug.Print "Tag [" & CStr(i) & "]" = " & CStr(vtValue) Next i End If Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] Posted by Rabi on Mon, Feb 9 2009 2:54 PM Thank you J on!! I will do that. Posted by Jon Summers on Fri, Feb 6 2009 12:00 PM Reference the MicroStationDGN.Application Library Rabi: Sub GetTagSet() 'Microstation Related Variable Declarations Dim myMSAppConn As MicroStationDGN.ApplicationObjectConnector Dim myMSApp As MicroStationDGN.Application 'Microstation Connection check Attach to existing or create new On Error Resume Next Set myMSAppConn = GetObject(, "MicroStationDGN.ApplicationObjectConnector") If Err.Number = 429 Then 'Set myMSAppConn = New MicroStationDGN.ApplicationObjectConnector Set myMSAppConn = CreateObject("MicroStationDGN.ApplicationObjectConnector") 'Set myMSApp = myMSAppConn.Application Err.Clear End If Set myMSApp = myMSAppConn.Application If you have succeeded in referencing the MicroStationDGN.Application application from Excel VBA, then prefer to get a MicroStationDGN object reference like this: Sub GetTagSet() 'Microstation Related Variable Declarations Dim oMSApp As MicroStationDGN.Application Set oMSApp = New MicroStationDGN.Application This approach gives you full access to the MicroStationDGN object library (press F2 in the VBA IDE to browse libraries). It also enables the VBA IDE to provide IntelliSense (Excel VBA recognises MicroStation VBA objects and their properties and methods). This article about VBA and Excel may help. Regards, J on Summers LA Solutions Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] Posted by Rabi on Wed, Feb 4 2009 10:06 PM Hello VBA programmers, I need your help debugging this code. I tried to control Microstation from EXCEL VBA but something is not working. When I run the macro, Microstation opens for a while and disappears. It doesn't stay open at all. Any suggestions to improve this code would be very helpful for me. Sub GetTagSet() 'Microstation Related Variable Declarations Dim myMSAppConn As MicroStationDGN.ApplicationObjectConnector Dim myMSApp As MicroStationDGN.Application 'Microstation Connection check Attach to existing or create new On Error Resume Next Set myMSAppConn = GetObject(, "MicroStationDGN.ApplicationObjectConnector") If Err.Number = 429 Then 'Set myMSAppConn = New MicroStationDGN.ApplicationObjectConnector Set myMSAppConn = CreateObject("MicroStationDGN.ApplicationObjectConnector") 'Set myMSApp = myMSAppConn.Application Err.Clear End If Set myMSApp = myMSAppConn.Application On Error GoTo 0 Dim myDGN As DesignFile Dim myTagSet As TagSet Dim myTagDef As TagDefinition Dim myTagDefs As TagDefinitions Dim myTag As TagElement Dim myEleEnum As ElementEnumerator Dim myEleFilter As New ElementScanCriteria 'Folder Related Variable Declarations Dim myFSO As New Scripting.FileSystemObject Dim myFolder As Scripting.Folder Dim myFile As Scripting.File 'Excel Related Variable Declarations Dim CurRow As Long Dim CurCol As Long 'MsgBox myActiveSheet CurRow = 2 CurCol = 2 Set myFolder = myFSO.GetFolder("C:\Documents and Settings\radhikari\Desktop\Microstation\Sheets") For Each myFile In myFolder.Files 'MsgBox "Its working upto here!" & " " & myFile.Type Select Case myFile.Type Case "Bentley MicroStation Design" 'MsgBox myFile.Name 'File Name and Merge Cells ThisWorkbook.ActiveSheet.Cells(CurRow, 1) = myFile.Path CurRow = CurRow + 1 'Open the File Set myDGN = myMSApp.OpenDesignFileForProgram(myFile.Path, True) Controlling Microstation fromExcel VBA - [Archived] MicroStation V8 XM Edition Programming Forum- MicroStation Programming - Be Communities by Bentley http://communities.bentley.com/products/microstation/microstation_programming/f/158/t/17031.aspx[5/27/2013 2:51:48 PM] VBA EXCEL programming 'Read TagSet On Error Resume Next Set myTagSet = myDGN.TagSets("STD-TITL") If myTagSet Is Nothing Then MsgBox "No Title Tags exists!", vbExclamation End If For Each myTagDefs In myTagSet ThisWorkbook.ActiveSheet.Cells(CurRow, CurCol) = myTagDef.Name CurCol = CurCol + 1 Next myDGN.Close Case Default MsgBox "Something is not working!" End Select Next Set myMSApp = Nothing Set myMSAppConn = Nothing End Sub
I will look forward toward hearing from you. Sincerely, Rabi Bentley Systems, Incorporated | Facebook | Twitter | YouTube Contact Us | Privacy Policy | Terms Of Use | Governance