Below is the code that we are going to look at:
myXLS_file = "C:\Users\Public\Documents\Autodesk\Inventor 2015\Templates\" & iProperties.Value("Custom", "Customer") & "-" & iProperties.Value("Project", "Project") & ".xls" excelApp = CreateObject("Excel.Application") excelApp.Visible = False excelApp.DisplayAlerts = False If dir(myXLS_file)<>"" Then excelWorkbook = excelApp.Workbooks.Open(myXLS_file) excelSheet = excelWorkbook.Worksheets(1).activate Else excelWorkbook = excelApp.Workbooks.Add End If With excelApp 'iproperties call out .range("A12").Select .ActiveCell.Value = "Project:" .range("A13").Select .ActiveCell.Value = "Customer:" .range("A14").Select .ActiveCell.Value = "Address Line 1:" .range("A15").Select .ActiveCell.Value = "Address Line 2:" .range("A16").Select .ActiveCell.Value = "Company:" .range("A17").Select .ActiveCell.Value = "Manager:" .range("A18").Select .ActiveCell.Value = "Engineer:" .range("A19").Select .ActiveCell.Value = "Rev Number:" 'iproperties info being exported .Range("B19").Select .ActiveCell.Value = iProperties.Value("Project", "Revision Number") .Range("B17").Select .ActiveCell.Value = iProperties.Value("Summary", "Manager") .Range("B16").Select .ActiveCell.Value = iProperties.Value("Summary", "Company") .Range("B12").Select .ActiveCell.Value = iProperties.Value("Project", "Project") .Range("B18").Select .ActiveCell.Value = iProperties.Value("Project", "Engineer") .Range("B13").Select .ActiveCell.Value = iProperties.Value("Custom", "Customer") .Range("B14").Select .ActiveCell.Value = iProperties.Value("Custom", "Address1") .Range("B15").Select .ActiveCell.Value = iProperties.Value("Custom", "Address2") End With excelApp.columns.AutoFit excelWorkbook.SaveAs(myXLS_file) excelWorkbook.Close excelApp.Quit excelApp = Nothing
At the beginning of this code we are defining the path in which the file is going to be saved and also defining the name of the excel file being created. In the naming of the excel document we are pulling Inventor iproperties out to give it the name.
One other thing that you will notice is the difference in which we are pulling out the information. In this form we are calling to activate a certain cell and then populate it with the text or property that we assign to it. Where as in the other parts we are calling to an excel app where as before we called out "GoExcel". With calling the excel app we are basically starting a new file from scratch which is why we can't do the "GoExcel". Once you have placed the code to fill in the cells how you want it then we do our coding to autofit the columns to the text, and then we do a save as which refers to the initial variable that we defined in the code. Then we call an excel close to close the file and quit to end the excelapp to make sure that Inventor fully closes out of the excel function.
No comments:
Post a Comment