Message 1 of 5

Not applicable
02-19-2019
10:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi folks, hope you all are going well.
My issue is related to GoExcel. FindRow. This snippet requires a name for "worksheet" but when I need to change the design I have to select a new database(xls) that has a different name in the excel worksheet (and different name of the xls file but this is not a problem, see the code bellow).
Is there a way to keep the code looking for the current activated worksheet from any file selected ?
Below, follow a code wrote by now, and obviously, I'm not an expert in this matter but as much as you, trying to learn more and more.
Dim oFileDlg As inventor.FileDialog = Nothing InventorVb.Application.CreateFileDialog(oFileDlg) oFileDlg.Filter = "Excel Files (*.xls;*.xlsx)|*.xls;*.xlsx" oFileDlg.DialogTitle = "Selecione o arquivo .xls extraido" oFileDlg.InitialDirectory = ThisDoc.Path oFileDlg.CancelError = True On Error Resume Next oFileDlg.ShowOpen() If Err.Number <> 0 Then MessageBox.Show("Arquivo nao selecionado.", "Operacao Cancelada") ElseIf oFileDlg.FileName <> "" Then NewFile = oFileDlg.FileName MessageBox.Show("O arquivo " & NewFile & " foi selecionado.", "Arquivo Selecionado") GoExcel.Open(NewFile,excelSheet) '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(NewFile) <> "" Then 'workbook exists, open it excelWorkbook = excelApp.Workbooks.Open(NewFile) 'set the first sheet active excelSheet = excelWorkbook.Worksheets(1).activate i=GoExcel.FindRow(NewFile,"excelSheet", "ELEMENT", "=", "CF3") CF3=GoExcel.CurrentRowValue("VALUE") i=GoExcel.FindRow(NewFile,"excelSheet", "ELEMENT", "=", "CF6") CF6=GoExcel.CurrentRowValue("VALUE") i=GoExcel.FindRow(NewFile,excelSheet , "ELEMENT", "=", "CF22") CF22=GoExcel.CurrentRowValue("VALUE") i=GoExcel.FindRow(NewFile,excelSheet, "ELEMENT", "=", "CF8") CF8=GoExcel.CurrentRowValue("VALUE") i=GoExcel.FindRow(NewFile, excelSheet, "ELEMENT", "=", "CF23") CF23=GoExcel.CurrentRowValue("VALUE") i=GoExcel.FindRow(NewFile, excelSheet, "ELEMENT", "=", "CF28") CF28=GoExcel.CurrentRowValue("VALUE") i=GoExcel.FindRow(NewFile, excelSheet, "ELEMENT", "=", "CF29") CF29=GoExcel.CurrentRowValue("VALUE") i=GoExcel.FindRow(NewFile,excelSheet, "ELEMENT", "=", "CF30") CF30=GoExcel.CurrentRowValue("VALUE") i=GoExcel.FindRow(NewFile,excelSheet, "ELEMENT", "=", "CF13") CF13=GoExcel.CurrentRowValue("VALUE") i=GoExcel.FindRow(NewFile,excelSheet, "ELEMENT", "=", "CF11") CF11=GoExcel.CurrentRowValue("VALUE") i=GoExcel.FindRow(NewFile,excelSheet, "ELEMENT", "=", "CF24") CF24=GoExcel.CurrentRowValue("VALUE") i=GoExcel.FindRow(NewFile,excelSheet, "ELEMENT", "=", "CF21") CF21=GoExcel.CurrentRowValue("VALUE") iLogicVb.UpdateWhenDone = True iProperties.Value("Summary", "Subject")= NewFile iProperties.Value("Custom", "External diameter [mm]")= CF3 iProperties.Value("Custom", "Internal diameter[mm]")= CF21 iProperties.Value("Custom", "Lenght [mm]")= CF24 InventorVb.DocumentUpdate() End If End If
Solved! Go to Solution.