I need to edit a couple of fields of a record in excel sheet, following certain operations in access.The code I am using follows (VBA access).
This code does not work: I get a compile error, "variable not defined", pointing to LookIn:=xlValues.Code:Private Sub AggiornaLibroSoci(NTes As String) Dim xlapp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet Dim xldata As Excel.Range Dim ExcelPath As String Dim rowNo As Long ExcelPath = CurrentProject.Path & "\" Set xlapp = CreateObject("Excel.Application") Set xlBook = xlapp.Workbooks.Open(ExcelPath & "LibroSoci.xlsm") Set xlSheet = xlBook.Worksheets("LibroSoci") xlSheet.Select xlSheet.Activate ' With ActiveSheet rowNo = xlBook.Worksheets("LibroSoci").Range("C:C").Find(What:=NTes, LookIn:=xlValues).Row xlBook.Worksheets("LibroSoci").Cells(rowNo, 12) = Year(Date) If Me.Nuova_TessElett <> "" Then xlBook.Worksheets("LibroSoci").Cells(rowNo, 37) = Me.Nuova_TessElett End If ' End With xlBook.Save xlBook.Close Set xlSheet = Nothing Set xlBook = Nothing Set xlapp = Nothing End Sub
Note that:
1) The excel table is linked to the access app, but I cannot edit the linked file directly: Starting from version 2003, Microsoft removed the possibility of editing linked excel files from access due to "legal reasons". So I have to work on the excel file itself.
2) I could import the file, make the changes and re-export the file: but I cannot re-export to the same file, only to a new one, so the process becomes cumbersome
3) The Microsoft Excel 16.0 Object library is already included
I am using Access and Excel in Office 2016.
What am I missing in trying to operate on excel file from Access VBA? Thank you for any suggesrtion.


Reply With Quote


Bookmarks