hexagon logo

Another Excel Script Problem

Hey, guys. Trying to make an excel script to output the dimensions that appear on the report. We have several that are not shown on the report that are used in the code for logic purposes.

Problem in code is where the xlsht.Range("D" + Count) = Nominal
code starts. No matter what I put after the equal sign, I get an OLE error.

The other "xlsht.Range" commands in the code work fine.

Suggestions?

xlsht.Range("D" + Count) = Nominal

Sub Main

'Excel Declarations
       Dim xlApp As Object
       Dim xlwrkbks As Object
       Dim xlwrkbk As Object
       Dim xlsht As Object
       Dim Count As Integer


       'PC-DMIS declarations 
       Dim PCDApp As Object
       Set PCDApp = CreateObject("PCDLRN.Application")
       Dim Part As Object
       Set Part = PCDApp.ActivePartProgram
       Dim Cmds As Object
       Set Cmds = Part.Commands
       Dim Cmd As Object
       Dim DCmd As Object
       Dim CCmd As Object
       Dim DCmdID As String






        'Variables From Part Program
        Dim VPART, VSERIALNUMBER, VPROGRAMID, VDATE, VTIME, VDESCRIPTION, VCMMOPERATOR, VLOCALCSV As Object
        Dim VREV As Object

        Set VREV = Part.GetVariableValue("VREV")
        Set VPART = Part.GetVariableValue("VPART")
        Set VDESCRIPTION = Part.GetVariableValue("VDESCRIPTION")
        Set VSERIALNUMBER = Part.GetVariableValue("VSERIALNUMBER")
        Set VPROGRAMID = Part.GetVariableValue("VPROGRAMID")
        Set VDATE = Part.GetVariableValue("VDATE")
        Set VTIME = Part.GetVariableValue("VTIME")
        Set VCMMOPERATOR = Part.GetVariableValue("VCMMOPERATOR")
        Set VLOCALCSV = Part.GetVariableValue("VLOCALCSV")

        'Open Excel And Template File
        Set xlApp = CreateObject("Excel.Application")
        Set xlwrkbks = xlApp.Workbooks
        Set xlwrkbk = xlApp.Workbooks.Open("D:\CMM_PROGRAMS\PC-DMIS_SUPPORT_FILES\EXCEL_FILES\TEMPLATE.CSV")
        Set xlsht = xlwrkbk.Worksheets("TEMPLATE")


        'EXCEL SHEET HEADER INFO
        xlsht.Range("A2").Value = "GE Aviation Batesville Composites Operation"
        xlsht.Range("A3").Value = "Part # :"
        xlsht.Range("A4").Value = "Date :"
        xlsht.Range("A5").Value = "Description :"
        xlsht.Range("A6").Value = "Serial # :"
        xlsht.Range("A7").Value = "Operator :"
        xlsht.Range("A8").Value = "Rev:"

        xlsht.Range("C3").Value = VPART.StringValue
        xlsht.Range("C4").Value = VDATE.StringValue
        xlsht.Range("C5").Value = VDESCRIPTION.StringValue
        xlsht.Range("C6").Value = VSERIALNUMBER.StringValue
        xlsht.Range("C7").Value = VCMMOPERATOR.StringValue
        xlsht.Range("C8").Value = VREV.StringValue

        xlsht.Range("A11").Value = "Dimension Name"
        xlsht.Range("D11").Value = "Nominal"
        xlsht.Range("E11").Value = "+TOL"
        xlsht.Range("F11").Value = "-TOL"
        xlsht.Range("G11").Value = "Measured"
        xlsht.Range("H11").Value = "MAX"
        xlsht.Range("I11").Value = "MIN"
        xlsht.Range("J11").Value = "Deviation"
        xlsht.Range("K11").Value = "OOT"
        xlsht.Range("L11").Value = "Bonus Tol"




        Count = Count + 1



       For Each Cmd In Cmds

            If Cmd.IsDimension Then

                Set DCmd = Cmd.DimensionCommand
                Set DCmdID = DCmd.ID

                If Not DCmd.OutputMode = "None" Then

                   xlsht.Range("D" + Count) = Nominal

                End If
            End If

        Next Cmd


        xlApp.Visible = True



End Sub
Parents
  • Decided to go a different way with this and adapt a script written by AndersI previously shared in this thread.(Thank You to both of you)

    The company IT dept is working on the VB installed on my computer as it is totally screwed, so I cannot use it for reference.


    ' Sub To Clear the Write variables
    
    Sub ClearRecord
      elType = "type"
      elName = "name"
      elValueType = "valuetype"
      elAct = 0
      elNom = 0
      elMax = 0
      elMin  = 0
      elDev = 0
      elMtol = 0
      elPtol = 0
      elOutTol = 0
      elBonusTol  = 0
    End Sub
    
    
    'Sub To Print a Line And space after the Line
    Sub PrintLine(FileNum%)
      If elStarted Then 
          Print #FileNum, elName; ","; elType; ","; elValueType; ","; elNom; ","; elAct; ","; elPtol; ","; elMtol; ","; elDev; ","; elOutTol; ","; elBonusTol
          Print #FileNum, ""
          elStarted = 0
      End If 
    
    End Sub
    
    
    
    Sub ExportAsCSV(FileName$)
    
    
    'PC-DMIS declarations 
    Dim PCDApp As Object
    Set PCDApp = CreateObject("PCDLRN.Application")
    Dim Part As Object
    Set Part = PCDApp.ActivePartProgram
    Dim Cmds As Object
    Set Cmds = Part.Commands
    Dim Cmd As Object
    Dim ID As String
    
    
    
    
    Dim ix As Integer
    Dim DCmd As  Object
    Dim DoOutput As Integer
    Dim State As Integer
    
    fNum = FreeFile
    Open FileName$ For Output As fNum
    
           
    'Variables From Part Program
            Dim VPART, VSERIALNUMBER, VPROGRAMID, VDATE, VTIME, VDESCRIPTION, VCMMOPERATOR, VLOCALCSV As Object
            Dim VREV As Object
    
            Set VREV = Part.GetVariableValue("VREV")
            Set VPART = Part.GetVariableValue("VPART")
            Set VDESCRIPTION = Part.GetVariableValue("VDESCRIPTION")
            Set VSERIALNUMBER = Part.GetVariableValue("VSERIALNUMBER")
            
            Set VDATE = Part.GetVariableValue("VDATE")
            
            Set VCMMOPERATOR = Part.GetVariableValue("VCMMOPERATOR")
            Set VLOCALCSV = Part.GetVariableValue("VLOCALCSV")
    
    Print #fNum, "GE Aviation - Batesville Composites Operation"
    Print #fNum, ""
    Print #fNum, "Part #:"; ","; ""; VPART.StringValue
    Print #fNum, "Serial #:"; ","; ""; VSERIALNUMBER.StringValue
    Print #fNum, "Description:"; ","; ""; VDESCRIPTION.StringValue
    Print #fNum, "Date:"; ","; ""; VDATE.StringValue
    Print #fNum, "CMM Operator:"; ","; ""; VCMMOPERATOR.StringValue
    Print #fNum, ""
    Print #fNum, "Dimension Name,Axis, Type, Nominal, Measured, +TOL, -TOL, Max, Min, Deviation, OutTol, BonusTol"
    
    elStarted = 0
    State = 1
    
    'Begin the Cases For the dimension types And actual data export
    '_______________________________________________________________
    
    For Each Cmd In Cmds
    
          If Cmd.IsDimension Then
    
                Set DCmd = Cmd.DimensionCommand
    
                 Select Case State
    
                          Case 1 
                            
                                    If (DCmd.OutputMode <> DIMOUTPUT_NONE) Then
                                        DoOutput = 1
                                     Else
                                         DoOutput = 0
                                      End If



    This section of the code is giving me trouble. The ".Type" returns an "unknown name" error. No idea. If I could use the VB library I could check to see if that was a valid command. I think it is...not sure what is wrong...

    Any ideas?


                                    If (DCmd.Type = DIMENSION_TRUE_START_POSITION) Then
                                         State = 2
                                    ElseIf (DCmd.Type = DIMENSION_START_LOCATION) Then
                                         State = 3
                                    End If
                                    
                                    If (DoOutput = 1) And (State = 1) Then
    
                     PrintLine(fNum)
                     ClearRecord
                     elType = DCmd.TypeDescription
                     elName = ID
                                     
                     If DCmd.AxisLetter = "D" Then
                            elValueType = "DIAM"
                     Elseif DCmd.AxisLetter = "R" Then
                     elValueType = "RAD"
                     Else
                     elValueType = DCmd.AxisLetter
                     End If
    
    
     ' ---------
                   elNom = DCmd.Nominal
                   ' 2005-11-16
                   If (Abs(DCmd.Deviation) > 0.00005) Then
     	              elDev = DCmd.Deviation
                   Else
                   	elDev = 0
                   End If
                    elAct = DCmd.Nominal + elDev
                   ' ---------
                   elMtol = DCmd.Minus
                   elPtol = DCmd.Plus
                   ' 2005-11-16
                   If (Abs(DCmd.OutTol) > 0.00005) Then
     	              elOutTol = DCmd.OutTol
                   Else
                   	elOutTol = 0
                   End If
                   ' ---------
                   elComment = ""
                   elStarted = 1
    
                 End If
    
                          Case 2                                                                            'True Position
    
     If (DoOutput = 1) Then
                   PrintLine(fNum)
                   ClearRecord
                    elType = DCmd.TypeDescription
                    elName = ID
                   ' 2005-11-17
                   If DCmd.AxisLetter = "D" Then
                       elValueType = "DIAM"
                    ElseIf DCmd.AxisLetter = "R" Then
                       elValueType = "RAD"
                   Else
                     elValueType = DCmd.AxisLetter
                   End If
                  ' ---------
                   elNom = DCmd.Nominal
                  ' 2005-11-16
                   If (Abs(DmisDimension.Deviation) > 0.00005) Then
    	               elDev = DCmd.Deviation
                   Else
                   	elDev = 0
                   End If
                   elAct = DCmd.Nominal + elDev
                   ' ---------
                   elMtol = DCmd.Minus
                   elPtol = DCmd.Plus
                   ' 2005-11-16
                   If (Abs(v.OutTol) > 0.00005) Then
     	              elOutTol = DCmd.OutTol
                   Else
                   	elOutTol = 0
                   End If
                   ' ---------
                   elComment = ""
                   elStarted = 1
                 End If
    
             Case 3 '                                                                                       Location
    
                 If (DoOutput = 1) Then
                   PrintLine(fNum)
                   ClearRecord
                   elType = DCmd.TypeDescription
                   elName = ID
                   ' 2005-11-17
                   If DCmd.AxisLetter = "D" Then
                       elValueType = "DIAM"
                   ElseIf DCmd.AxisLetter = "R" Then
                       elValueType = "RAD"
                   Else
                      elValueType = DCmd.AxisLetter
                   End If
                   ' ---------
                   elNom = DCmd.Nominal
                   ' 2005-11-16
                  If (Abs(DCmd.Deviation) > 0.00005) Then
    	              elDev = DCmd.Deviation
                  Else
                  	elDev = 0
                  End If
                  elAct = DCmd.Nominal + elDev
                  ' ---------
                  elMtol = -DCmd.Minus
                  elPtol = DCmd.Plus
                  ' 2005-11-16
                  If (Abs(DCmd.OutTol) > 0.00005) Then
    	              elOutTol = DCmd.OutTol
                  Else
                  	elOutTol = 0
                  End If
                  ' ---------
                  elComment = ""
                  elStarted = 1
                End If
    
          End Select
    
    Set DCmd = Nothing
    
                  End If
    
        Set DCmd = Nothing
    
    
    
    
    
    Next Cmd
    
    End Sub
    
    Sub Main(FileName$)
    
        'ExportAsCSV(FileName$) 'For Deployment
        ExportAsCSV("Export.CSV") 'For Testing
    
    End Sub
Reply
  • Decided to go a different way with this and adapt a script written by AndersI previously shared in this thread.(Thank You to both of you)

    The company IT dept is working on the VB installed on my computer as it is totally screwed, so I cannot use it for reference.


    ' Sub To Clear the Write variables
    
    Sub ClearRecord
      elType = "type"
      elName = "name"
      elValueType = "valuetype"
      elAct = 0
      elNom = 0
      elMax = 0
      elMin  = 0
      elDev = 0
      elMtol = 0
      elPtol = 0
      elOutTol = 0
      elBonusTol  = 0
    End Sub
    
    
    'Sub To Print a Line And space after the Line
    Sub PrintLine(FileNum%)
      If elStarted Then 
          Print #FileNum, elName; ","; elType; ","; elValueType; ","; elNom; ","; elAct; ","; elPtol; ","; elMtol; ","; elDev; ","; elOutTol; ","; elBonusTol
          Print #FileNum, ""
          elStarted = 0
      End If 
    
    End Sub
    
    
    
    Sub ExportAsCSV(FileName$)
    
    
    'PC-DMIS declarations 
    Dim PCDApp As Object
    Set PCDApp = CreateObject("PCDLRN.Application")
    Dim Part As Object
    Set Part = PCDApp.ActivePartProgram
    Dim Cmds As Object
    Set Cmds = Part.Commands
    Dim Cmd As Object
    Dim ID As String
    
    
    
    
    Dim ix As Integer
    Dim DCmd As  Object
    Dim DoOutput As Integer
    Dim State As Integer
    
    fNum = FreeFile
    Open FileName$ For Output As fNum
    
           
    'Variables From Part Program
            Dim VPART, VSERIALNUMBER, VPROGRAMID, VDATE, VTIME, VDESCRIPTION, VCMMOPERATOR, VLOCALCSV As Object
            Dim VREV As Object
    
            Set VREV = Part.GetVariableValue("VREV")
            Set VPART = Part.GetVariableValue("VPART")
            Set VDESCRIPTION = Part.GetVariableValue("VDESCRIPTION")
            Set VSERIALNUMBER = Part.GetVariableValue("VSERIALNUMBER")
            
            Set VDATE = Part.GetVariableValue("VDATE")
            
            Set VCMMOPERATOR = Part.GetVariableValue("VCMMOPERATOR")
            Set VLOCALCSV = Part.GetVariableValue("VLOCALCSV")
    
    Print #fNum, "GE Aviation - Batesville Composites Operation"
    Print #fNum, ""
    Print #fNum, "Part #:"; ","; ""; VPART.StringValue
    Print #fNum, "Serial #:"; ","; ""; VSERIALNUMBER.StringValue
    Print #fNum, "Description:"; ","; ""; VDESCRIPTION.StringValue
    Print #fNum, "Date:"; ","; ""; VDATE.StringValue
    Print #fNum, "CMM Operator:"; ","; ""; VCMMOPERATOR.StringValue
    Print #fNum, ""
    Print #fNum, "Dimension Name,Axis, Type, Nominal, Measured, +TOL, -TOL, Max, Min, Deviation, OutTol, BonusTol"
    
    elStarted = 0
    State = 1
    
    'Begin the Cases For the dimension types And actual data export
    '_______________________________________________________________
    
    For Each Cmd In Cmds
    
          If Cmd.IsDimension Then
    
                Set DCmd = Cmd.DimensionCommand
    
                 Select Case State
    
                          Case 1 
                            
                                    If (DCmd.OutputMode <> DIMOUTPUT_NONE) Then
                                        DoOutput = 1
                                     Else
                                         DoOutput = 0
                                      End If



    This section of the code is giving me trouble. The ".Type" returns an "unknown name" error. No idea. If I could use the VB library I could check to see if that was a valid command. I think it is...not sure what is wrong...

    Any ideas?


                                    If (DCmd.Type = DIMENSION_TRUE_START_POSITION) Then
                                         State = 2
                                    ElseIf (DCmd.Type = DIMENSION_START_LOCATION) Then
                                         State = 3
                                    End If
                                    
                                    If (DoOutput = 1) And (State = 1) Then
    
                     PrintLine(fNum)
                     ClearRecord
                     elType = DCmd.TypeDescription
                     elName = ID
                                     
                     If DCmd.AxisLetter = "D" Then
                            elValueType = "DIAM"
                     Elseif DCmd.AxisLetter = "R" Then
                     elValueType = "RAD"
                     Else
                     elValueType = DCmd.AxisLetter
                     End If
    
    
     ' ---------
                   elNom = DCmd.Nominal
                   ' 2005-11-16
                   If (Abs(DCmd.Deviation) > 0.00005) Then
     	              elDev = DCmd.Deviation
                   Else
                   	elDev = 0
                   End If
                    elAct = DCmd.Nominal + elDev
                   ' ---------
                   elMtol = DCmd.Minus
                   elPtol = DCmd.Plus
                   ' 2005-11-16
                   If (Abs(DCmd.OutTol) > 0.00005) Then
     	              elOutTol = DCmd.OutTol
                   Else
                   	elOutTol = 0
                   End If
                   ' ---------
                   elComment = ""
                   elStarted = 1
    
                 End If
    
                          Case 2                                                                            'True Position
    
     If (DoOutput = 1) Then
                   PrintLine(fNum)
                   ClearRecord
                    elType = DCmd.TypeDescription
                    elName = ID
                   ' 2005-11-17
                   If DCmd.AxisLetter = "D" Then
                       elValueType = "DIAM"
                    ElseIf DCmd.AxisLetter = "R" Then
                       elValueType = "RAD"
                   Else
                     elValueType = DCmd.AxisLetter
                   End If
                  ' ---------
                   elNom = DCmd.Nominal
                  ' 2005-11-16
                   If (Abs(DmisDimension.Deviation) > 0.00005) Then
    	               elDev = DCmd.Deviation
                   Else
                   	elDev = 0
                   End If
                   elAct = DCmd.Nominal + elDev
                   ' ---------
                   elMtol = DCmd.Minus
                   elPtol = DCmd.Plus
                   ' 2005-11-16
                   If (Abs(v.OutTol) > 0.00005) Then
     	              elOutTol = DCmd.OutTol
                   Else
                   	elOutTol = 0
                   End If
                   ' ---------
                   elComment = ""
                   elStarted = 1
                 End If
    
             Case 3 '                                                                                       Location
    
                 If (DoOutput = 1) Then
                   PrintLine(fNum)
                   ClearRecord
                   elType = DCmd.TypeDescription
                   elName = ID
                   ' 2005-11-17
                   If DCmd.AxisLetter = "D" Then
                       elValueType = "DIAM"
                   ElseIf DCmd.AxisLetter = "R" Then
                       elValueType = "RAD"
                   Else
                      elValueType = DCmd.AxisLetter
                   End If
                   ' ---------
                   elNom = DCmd.Nominal
                   ' 2005-11-16
                  If (Abs(DCmd.Deviation) > 0.00005) Then
    	              elDev = DCmd.Deviation
                  Else
                  	elDev = 0
                  End If
                  elAct = DCmd.Nominal + elDev
                  ' ---------
                  elMtol = -DCmd.Minus
                  elPtol = DCmd.Plus
                  ' 2005-11-16
                  If (Abs(DCmd.OutTol) > 0.00005) Then
    	              elOutTol = DCmd.OutTol
                  Else
                  	elOutTol = 0
                  End If
                  ' ---------
                  elComment = ""
                  elStarted = 1
                End If
    
          End Select
    
    Set DCmd = Nothing
    
                  End If
    
        Set DCmd = Nothing
    
    
    
    
    
    Next Cmd
    
    End Sub
    
    Sub Main(FileName$)
    
        'ExportAsCSV(FileName$) 'For Deployment
        ExportAsCSV("Export.CSV") 'For Testing
    
    End Sub
Children
No Data