cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Exporting Mathcad 15 values to CSV/text file file using VBS

TD_11399801
1-Newbie

Exporting Mathcad 15 values to CSV/text file file using VBS

Hello, 

 

I was wondering if I could get help with a VBS script to export bolded text with an equal sign from a Mathcad file to a cvs/txt file 

 

An example of text to export is 

TD_11399801_0-1729690051919.png

Val1 = 1 and Val2 =2  would print to the cvs/txt file as

                Val1,”1”

                Val2,”2”

While the remaining text would be ignored. 

 

Attached is a vbs script that gets all of the text from a Mathcad, but I need to add a conditional that will only print text if it is Bolded and has an equals (=) sign.

I cannot work on this at work since running scripts is blocked and I am working on permission to run this one. 

2 REPLIES 2

Hi @TD_11399801,

Thank you for your question!

Your post appears well documented but has not yet received any response. I am replying to raise awareness. Hopefully, another community member will be able to help.

Also, feel free to add any additional information you think might be relevant.

 

Best regards,

Catalina
PTC Community Moderator

Hi,

Sorry it has taken so long to respond.

 

Every region in the worksheet has a property called "Tag".  You can set this for individual regions to the same value. 

It is possible in vbscript to read the Tag property to see  which ones are tagged and respond accordingly.

Right click  on a region in Mathcad 15 and select Properties.

You get this dialog box to set the Tag.

Capture2.JPG

 

' MathcadExtractText.vbs
Set Mathcad = CreateObject("Mathcad.Application")
Set Worksheet = Mathcad.Worksheets.Open("F:\Prime\VB\worksheet.xmcd")

Set TextFile = CreateObject("Scripting.FileSystemObject").CreateTextFile("F:\Prime\VB\output.txt", True)

For Each Region In Worksheet.Regions
    If Region.Type = 1 Then ' denotes an expression region in Mathcad
        bstr = Region.Tag' Region.XML does not work either.
        
        tokens = Split(bstr, vbCrLf)
        For i = 0 To UBound(tokens)
    		 TextFile.WriteLine(tokens(i))
		Next
        
        
    End If
Next

TextFile.Close
Worksheet.Close
Mathcad.Quit

 

 

 

ThisOne
ThisOne

 

Announcements

Top Tags