none
Adding a note that contains equations created from equation tools in Word RRS feed

  • Question

  • I have the below code but it does not include the equation as it appears on the original checklist.  How do I include these equations to appear exactly as shown? 

    Private Sub Document_Close()
        Call ExportCheckedItemsToNewFile
    End Sub

    'The main method
    Sub ExportCheckedItemsToNewFile()
        conf = MsgBox("It'll take some time to export checked items into a new file, do you want to continue?", vbYesNo, "Confirmation")
        If conf = vbNo Then
            Exit Sub
        End If

        Dim i%, j%, content$, newFileName$
        newFileName = "C:/Common/drw_notes.docx"
       
        'Determine if the new file exists, if it doesn't, create a new one
        If FileExists(newFileName) = False Then
            Set newWord = CreateObject("Word.Application")
            newWord.Visible = False
            Set newDoc = newWord.Documents.Add
            newDoc.SaveAs (newFileName)
            newDoc.Close
            newWord.Quit
        End If
       
        'Open the new file, prepare to export the checked items into it
        Set newWord = CreateObject("Word.Application")
        newWord.Visible = False
        Set newDoc = newWord.Documents.Open(newFileName)
       
        'Enumerate all the Checkbox content controls
        For i = 1 To ActiveDocument.ContentControls.Count
            If ActiveDocument.ContentControls(i).Type = wdContentControlCheckBox Then
                If ActiveDocument.ContentControls(i).Checked Then
                   
                    'Determine if this is the last Checkbox in the document
                    If i < ActiveDocument.ContentControls.Count Then
                        startRange = ActiveDocument.ContentControls(i).Range.End
                        endRange = ActiveDocument.ContentControls(i + 1).Range.Start
                        content = ActiveDocument.Range(startRange, endRange).Text
                    ElseIf i = ActiveDocument.ContentControls.Count Then
                        startRange = ActiveDocument.ContentControls(i).Range.End
                        endRange = ActiveDocument.Range.End
                        content = ActiveDocument.Range(startRange, endRange).Text
                    End If

                    j = j + 1
                    'Export the checked items into the new file
                    If content Like "FN*" Then
                        content = ReplaceFirstFoundString(content, "FN[0-9]+", "FN" & j)
                    ElseIf content Like "GN*" Then
                        content = ReplaceFirstFoundString(content, "GN[0-9]+", "GN" & j)
                    End If
                   
                    newDoc.content.InsertAfter content & Chr(10)
                    newDoc.Save

                End If
            Else
                'Make sure there're no other type of content controls in the document
                MsgBox "There are Non-Checkbox content controls in this document."
            End If
        Next
       
        newDoc.Close
        newWord.Quit
        MsgBox "Complete! Please check file:" & newFileName
        ActiveDocument.Save
    End Sub

    'Check if a file exists
    Private Function FileExists(filename As String) As Boolean
        Dim fso As Object
        Set fso = CreateObject("Scripting.FileSystemObject")
        If fso.FileExists(filename) Then FileExists = True Else FileExists = False
    End Function

    'Use regular expression to replace a found string to another string
    Private Function ReplaceFirstFoundString(srcString As String, pattern As String, replaceString As String) As String
        Set objRegEx = CreateObject("vbscript.regexp")
        objRegEx.Global = True
        objRegEx.IgnoreCase = True
        objRegEx.MultiLine = True
        objRegEx.pattern = pattern
       
        ReplaceFirstFoundString = objRegEx.Replace(srcString, replaceString)
    End Function

     

    Wednesday, January 29, 2014 4:48 PM

All replies

  • What is your equations?
    Thursday, January 30, 2014 3:37 AM
  • The equations are drawing notes information.  I'm trying to add a snapshot but the system won't allow me too.  Is there another way I could send this to you?

    Thursday, January 30, 2014 9:26 PM
  • MASTER PART DEFINITION IS CONTROLLED BY 2Uxxxxxx-XXX. MODELS ARE LOCATED IN THE NX CAD ENVIRONMENT, WITH STEP FILES IN EPIC. UPDATES TO THIS DOCUMENT MUST ORIGINATE FROM THE MASTER DATA FILE. A SURFACE PROFILE OF    (EQUATION HERE:  .060) APPLIED ALL OVER UNLESS OTHERWISE SPECIFIED IN THIS 2D DRAWING. APPLY (EQUATION HERE: TRUE POSITION WITHIN A DIAMETER OF .030 AT MAX MATERIAL CONDITION TO DATUMS A, B & C) AND A SIZE TOLERANCE OF (EQUATION HERE:  +.006 TO -.001) FOR ALL HOLES UNLESS OTHERWISE SPECIFIED.  ETC..... 

      

    Friday, February 7, 2014 7:11 PM
  • All this tells us, really, is that you're trying to extract information from a non-Microsoft program and put it into Word? In that case, it's probably better to pursue this in a forum dedicated to that other software as chances are slim you'll find someone in a WORD forum that knows how to pull an equation from ?NX CAD????


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, February 8, 2014 4:08 PM
    Moderator
  • The equation is created and located in Word.  I'am not extracting this from a non-Microsoft program. 
    Monday, February 10, 2014 3:09 PM