Message 1 of 5

Not applicable
08-22-2019
10:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am trying to get illogic to pull a excel template, fill in specific cells, create a new folder and save the worksheet in the new folder. I have a code that works mostly but it saves the excel sheet in the wrong folder.
I have attached the code below & I'm using inventor 2020.
Dim oDOc As DrawingDocument name = ThisDoc.FileName (False) oPath = ThisDoc.Path oName = "Drawing Review" oDOc = ThisApplication.ActiveDocument path_and_name = ThisDoc.PathAndFileName(False) 'get target folder path from the file's path + DWF oFolder = oPath & "\" & oName 'Check for the DWF folder and create it if it does not exist If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If Dim oSheet As Sheet oSheet = oDOc.Sheets.Item(1) Dim oPartList As PartsList oPartList = oSheet.PartsLists.Item(1) Dim oOptions As NameValueMap oOptions = ThisApplication.TransientObjects.CreateNameValueMap myXLS_File = ThisDoc.PathAndFileName(True) & ".xlsx" 'get the Inventor user name from the Inventor Options myName= ThisApplication.GeneralOptions.UserName '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 'check for existing file If Dir(myXLS_File) <> "" Then 'workbook exists, open it excelWorkbook = excelApp.Workbooks.Open(myXLS_File) 'set the first sheet active excelSheet = excelWorkbook.Worksheets(1).activate Else 'workbook does NOT exist, so create a new one using the default template 'excelWorkbook = excelApp.Workbooks.Add ' or use this syntax to specify a template to use excelWorkbook = excelApp.Workbooks.Add ("\\Fig015\cad\0-0-Veritas\Drawing Checklist\Drawing Checklist.xlsm") End If 'Insert data into Excel. With excelApp .Range("A4").Select .ActiveCell.FormulaR1C1 = iProperties.Value("Custom", "Order Number") .Range("C4").Select .ActiveCell.FormulaR1C1 = iProperties.Value("Custom", "Client Name") .Range("F4").Select .ActiveCell.FormulaR1C1 = iProperties.Value("Custom", "Project Name") .Range("K4").Select .ActiveCell.FormulaR1C1 = ThisApplication.GeneralOptions.UserName .Range("I4").Select .ActiveCell.FormulaR1C1 = iProperties.Value("Custom", "Project Team") End With 'set all of the columns to autofit 'excelApp.Columns.AutoFit 'save the file 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
Solved! Go to Solution.