Results 1 to 8 of 8

Thread: Work on excel file from access vba

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    6
    Rep Power
    0

    Work on excel file from access vba

    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).

    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
    This code does not work: I get a compile error, "variable not defined", pointing to LookIn:=xlValues.
    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.
    Last edited by DocAElstein; 02-08-2020 at 02:27 PM. Reason: https://www.excelforum.com/access-programming-vba-macros/1305368-open-and-edit-an-excel-file-from-access-vba.html#post5274177

Similar Threads

  1. Replies: 6
    Last Post: 09-03-2019, 10:26 AM
  2. Unable to import excel file in Access 2007
    By excel_1317 in forum Access Help
    Replies: 9
    Last Post: 09-23-2013, 07:52 AM
  3. Run SQL In MS-Access From Excel VBA
    By bobdole22 in forum Excel Help
    Replies: 4
    Last Post: 09-12-2013, 01:35 AM
  4. Replies: 1
    Last Post: 03-07-2013, 11:42 AM
  5. Replies: 3
    Last Post: 12-20-2012, 11:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •