Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I had developed an ilogic to get the flat pattern dimensions in a specific format exported to excel sheet for all the open part files. But i am getting an error saying Excel cell not found (bad cell address?): "A-93" i understand the error but i am not able to troubleshoot the same.
Code is as below: Please some could help regarding this
Sub Main ThisApplication.CommandManager.ControlDefinitions.Item("AppZoomallCmd").Execute For Each oDoc As Document In ThisApplication.Documents If TypeOf oDoc Is PartDocument Then Dim partDoc As PartDocument = oDoc If partDoc.ComponentDefinition.Type <> ObjectTypeEnum.kSheetMetalComponentDefinitionObject Then 'MsgBox("A sheet metal document must be open.") Continue For End If currentStyle = SheetMetal.GetActiveStyle() If currentStyle = ("ALUM#11") Then ABC = "12002EB5NF" XYZ = ") .125 AL" End If If currentStyle = ("STEEL#11") Then ABC = "10101ACS60" XYZ = ") 11GA ST" End If Dim oDoc1 As PartDocument oDoc1 = ThisApplication.ActiveDocument Dim oCompDef As SheetMetalComponentDefinition oCompDef = oDoc1.ComponentDefinition If oCompDef.HasFlatPattern = False Then oCompDef.Unfold oCompDef.FlatPattern.ExitEdit End If filename2 = ThisDoc.PathAndFileName(False) index11 = InStrRev(filename2, "\") ActiveFileName = Mid(filename2,index11+1) ActiveFileName2 = ActiveFileName.split(".")(0) ActiveFileName2Length = Len(ActiveFileName2) 'index12 = InStrRev(ActiveFileName2,"H") 'ActiveFileName3 = Left(ActiveFileName2, index12 - 1) index13 = InStrRev(ActiveFileName2,"H") PartName = Right(ActiveFileName2, ActiveFileName2Length - index13 + 1) index3 = InStrRev(filename2,"\") folderPath=Left(filename2,index3) Dim oPath As String = folderPath index5 = InStrRev(filename2,"\") fullFileName = Mid(filename2,index5+1) newFileName1 = fullFileName.split(".")(0) index4 = InStrRev(newFileName1,"H") newFileName = Left(newFileName1,index4-1) 'define Excel Application object excelApp = CreateObject("Excel.Application") 'set Excel to run visibly, change to false if you want to run it invisibly excelApp.Visible = False 'suppress prompts (such as the compatibility checker) excelApp.DisplayAlerts = False 'define the file to create/open myXLS_File = (oPath & newFileName & ".xlsx") ' "C:\Temp\FlatExtent.xlsx" 'check for existing file If Not Dir(myXLS_File) <> "" Then 'workbook does NOT exist, so create a new one excelWorkbook = excelApp.Workbooks.Add excelWorkbook.SaveAs (myXLS_File) 'close the workbook and the Excel Application 'uncomment if you want to close the xls file at the end excelWorkbook.Close excelApp.Quit excelApp = Nothing End If ' Open excel Worksheet = myXLS_File Sheetno = ("Sheet1") GoExcel.Open(Worksheet, Sheetno) 'If GoExcel.FindRow(myXLS_File,"Sheet1","ITEM",PartName) Then ' GoTo Notification 'End If If String.IsNullOrEmpty(GoExcel.CellValue("A" & 1)) Then GoExcel.CellValue("A" & 1) = "ITEM" GoExcel.CellValue("B" & 1) = "SYM" GoExcel.CellValue("C" & 1) = "DESCRIPTION" GoExcel.CellValue("D" & 1) = "PART NUMBER" End If ' Define Range RowStart = 3 RowEnd = 100 For count = RowStart To RowEnd ' If it's blank count it If String.IsNullOrEmpty(GoExcel.CellValue("C" & count)) Then i = i + 1 End If Next ' Next empty row is max rows minus blank rows plus one oRow = RowEnd - i + 1 oRow1 = oRow + 1 GoExcel.CellValue("A" & oRow) = PartName GoExcel.CellValue("C" & oRow) = Round(SheetMetal.FlatExtentsLength,3) & " X " & Round(SheetMetal.FlatExtentsWidth,3) & " " & iProperties.Value("Custom", "Title Line 3") GoExcel.CellValue("C" & oRow1) = ("LXW " & Round(SheetMetal.FlatExtentsLength,3) & " X " & Round(SheetMetal.FlatExtentsWidth,3)& XYZ) GoExcel.CellValue("D" & oRow) = ABC 'add a small delay between text field updates End If Next Threading.Thread.Sleep(2000) 'in ms GoExcel.Save GoExcel.Close 'define Excel Application object excelApp = CreateObject("Excel.Application") 'set Excel to run visibly, change to false if you want to run it invisibly excelApp.Visible = False 'suppress prompts (such as the compatibility checker) excelApp.DisplayAlerts = False 'workbook exists, open it excelWorkbook = excelApp.Workbooks.Open(myXLS_File) ExcelSheet = ExcelWorkbook.Worksheets(1) 'set all of the columns to autofit excelApp.Columns.AutoFit excelWorkbook.Save 'close the workbook and the Excel Application 'uncomment if you want to close the xls file at the end excelWorkbook.Close excelApp.Quit excelApp = Nothing GoExcel.Save GoExcel.Close MsgBox("Flat Pattern Extents Copied !") End Sub
Solved! Go to Solution.