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
  • Had to split the code into 2 sections.

    Case 3 '  Location
    
                If (DmisDimension.OutputMode <> DIMOUTPUT_NONE) Then
                  DoOutput = 1
                Else
                  DoOutput = 0
                End If
    
    
    
                If (DoOutput = 1) And (State = 3) Then
                  PrintLine(fNum)
                  ClearRecord
                  elType = DmisCommand.TypeDescription
                  elName = ID
                  ' 2005-11-17
                  If DmisDimension.AxisLetter = "D" Then
                      elValueType = "DIAM"
                  ElseIf DmisDimension.AxisLetter = "R" Then
                      elValueType = "RAD"
                  Else
                    elValueType = DmisDimension.AxisLetter
                  End If
                  ' ---------
                  elNom = DmisDimension.Nominal
                  ' 2005-11-16
                  If (Abs(DmisDimension.Deviation) > 0.00009) Then
    	              elDev = DmisDimension.Deviation
                  Else
                  	elDev = 0
                  End If
                  elAct = DmisDimension.Nominal + elDev
                  ' ---------
                  elMtol = -DmisDimension.Minus
                  elPtol = DmisDimension.Plus
                  ' 2005-11-16
                  If (Abs(DmisDimension.OutTol) > 0.00009) Then
    	              elOutTol = DmisDimension.OutTol
                  Else
                  	elOutTol = 0
                  End If
                  ' ---------
    
                   elMax = ""
                  elMin = ""
    
                  If (Abs(DmisDimension.Bonus) > .00009) Then
                             elBTol = DmisDimension.Bonus
                  Else
                            elBTol = 0
                  End If 
    
    
                  elStarted = 1
                End If
    
    
          Case 4        'For Profile Dimensions
    
    
            If (DoOutput = 1) And (State = 4) Then
    
                If (DmisDimension.OutputMode <> DIMOUTPUT_NONE) Then
                  DoOutput = 1
                Else
                  DoOutput = 0
                End If
    
    
    
                  PrintLine(fNum)
                  ClearRecord
                  elType = DmisCommand.TypeDescription
                  elName = ID
    
                  If DmisDimension.AxisLetter = "D"  Then
                      elValueType = "DIAM"
                  ElseIf DmisDimension.AxisLetter = "R" Then
                      elValueType = "RAD"
                  Else
                    elValueType = DmisDimension.AxisLetter
                  End If
    
                  '---------------------------------
    
                  elNom = DmisDimension.Nominal
    
                  '--------------------------------------------
                  elMtol = -DmisDimension.Minus
                  elPtol = DmisDimension.Plus
    
                  '-------------------------------------------
    
                  If (Abs(DmisDimension.Max) >.00009) Then
                        elMax = DmisDimension.Max
                  Else 
                        elMax = 0
                  End If
    
                  '-------------------------------------------
    
                  If (Abs(DmisDimension.Min) >.00009) Then
                        elMax = DmisDimension.Min
                  Else 
                        elMin = 0
                  End If
    
    
    
                  '---------------------------------
                  elDev = ""
                  elAct = ""
                  elBTol = ""
                  '----------------------------------
    
    
    
    
            End If 
    
          End Select
    
          Set DmisDimension = Nothing
    
        ElseIf (DmisCommand.Type = DIMENSION_TRUE_END_POSITION) Then
    
          State = 1
    
        ElseIf (DmisCommand.Type = DIMENSION_END_LOCATION) Then
    
          State = 1
    
        End If
    
        Set DmisCommand = Nothing
    
      Next Cmd
    
      Set DmisCommands = Nothing
      Set DmisPart = Nothing
      Set DmisApp = Nothing
    
     PrintLine(fNum)
    
      Close #fNum
      Print "Klart"
    End Sub
    
    Sub Main(FileName$)
      'ExportAsCSV(FileName$) ' For deployment
       ExportAsCSV("EXPORT.csv") ' For testing
    End Sub
Reply
  • Had to split the code into 2 sections.

    Case 3 '  Location
    
                If (DmisDimension.OutputMode <> DIMOUTPUT_NONE) Then
                  DoOutput = 1
                Else
                  DoOutput = 0
                End If
    
    
    
                If (DoOutput = 1) And (State = 3) Then
                  PrintLine(fNum)
                  ClearRecord
                  elType = DmisCommand.TypeDescription
                  elName = ID
                  ' 2005-11-17
                  If DmisDimension.AxisLetter = "D" Then
                      elValueType = "DIAM"
                  ElseIf DmisDimension.AxisLetter = "R" Then
                      elValueType = "RAD"
                  Else
                    elValueType = DmisDimension.AxisLetter
                  End If
                  ' ---------
                  elNom = DmisDimension.Nominal
                  ' 2005-11-16
                  If (Abs(DmisDimension.Deviation) > 0.00009) Then
    	              elDev = DmisDimension.Deviation
                  Else
                  	elDev = 0
                  End If
                  elAct = DmisDimension.Nominal + elDev
                  ' ---------
                  elMtol = -DmisDimension.Minus
                  elPtol = DmisDimension.Plus
                  ' 2005-11-16
                  If (Abs(DmisDimension.OutTol) > 0.00009) Then
    	              elOutTol = DmisDimension.OutTol
                  Else
                  	elOutTol = 0
                  End If
                  ' ---------
    
                   elMax = ""
                  elMin = ""
    
                  If (Abs(DmisDimension.Bonus) > .00009) Then
                             elBTol = DmisDimension.Bonus
                  Else
                            elBTol = 0
                  End If 
    
    
                  elStarted = 1
                End If
    
    
          Case 4        'For Profile Dimensions
    
    
            If (DoOutput = 1) And (State = 4) Then
    
                If (DmisDimension.OutputMode <> DIMOUTPUT_NONE) Then
                  DoOutput = 1
                Else
                  DoOutput = 0
                End If
    
    
    
                  PrintLine(fNum)
                  ClearRecord
                  elType = DmisCommand.TypeDescription
                  elName = ID
    
                  If DmisDimension.AxisLetter = "D"  Then
                      elValueType = "DIAM"
                  ElseIf DmisDimension.AxisLetter = "R" Then
                      elValueType = "RAD"
                  Else
                    elValueType = DmisDimension.AxisLetter
                  End If
    
                  '---------------------------------
    
                  elNom = DmisDimension.Nominal
    
                  '--------------------------------------------
                  elMtol = -DmisDimension.Minus
                  elPtol = DmisDimension.Plus
    
                  '-------------------------------------------
    
                  If (Abs(DmisDimension.Max) >.00009) Then
                        elMax = DmisDimension.Max
                  Else 
                        elMax = 0
                  End If
    
                  '-------------------------------------------
    
                  If (Abs(DmisDimension.Min) >.00009) Then
                        elMax = DmisDimension.Min
                  Else 
                        elMin = 0
                  End If
    
    
    
                  '---------------------------------
                  elDev = ""
                  elAct = ""
                  elBTol = ""
                  '----------------------------------
    
    
    
    
            End If 
    
          End Select
    
          Set DmisDimension = Nothing
    
        ElseIf (DmisCommand.Type = DIMENSION_TRUE_END_POSITION) Then
    
          State = 1
    
        ElseIf (DmisCommand.Type = DIMENSION_END_LOCATION) Then
    
          State = 1
    
        End If
    
        Set DmisCommand = Nothing
    
      Next Cmd
    
      Set DmisCommands = Nothing
      Set DmisPart = Nothing
      Set DmisApp = Nothing
    
     PrintLine(fNum)
    
      Close #fNum
      Print "Klart"
    End Sub
    
    Sub Main(FileName$)
      'ExportAsCSV(FileName$) ' For deployment
       ExportAsCSV("EXPORT.csv") ' For testing
    End Sub
Children
No Data