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. #2
    Hello roberto21,
    I don't have Access.
    I don't have any experience with Access
    So I might not be able to help too much…


    But some general comments..

    _ 1) If the error first occurs at this line,
    rowNo = xlBook.Worksheets("LibroSoci").Range("C:C").Find(W hat:=NTes, LookIn:=xlValues).Row
    then I assume that the macro opened the Excel Workbook as you expected. Is that the case?

    _ 2) How are you Calling this macro ?


    ….
    _.____________________


    I tried this short test:
    I made a workbook , "LibroSoci.xls" , and in a worksheet "LibroSoci" , I put some text in like this,
    _____ Workbook: LibroSoci.xls ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    E
    1
    2
    3
    xxx
    4
    Worksheet: LibroSoci

    I then saved and closed the file.


    I then ran the adaptation of your macro shown below from an Excel File which was opened and which is in the same Folder as the newly created file, "LibroSoci.xls".

    The result of running Sub CallSubAggiornaLibroSoci() is that the file "LibroSoci.xls" is opened , the rowNo is correctly determined to be 3, and so the worksheet, ""LibroSoci" is modified to this:
    _____ Workbook: LibroSoci.xls ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    E
    1
    2
    3
    xxx
    2020
    4
    Worksheet: LibroSoci

    The file "LibroSoci.xls" is then saved and closed


    I am not sure if I can help much more as I am not familiar with ACCESS so am not too sure what it is you are trying to do.
    But my test suggest that your basic coding idea should work.


    _._____

    Just one last wild guess… You might want to try changing you signature line to
    Private Sub AggiornaLibroSoci(ByVal NTes As String)



    Molly

    _._______________

    Code:
    Sub CallSubAggiornaLibroSoci()
     Call AggiornaLibroSoci("xxx")
    End Sub
    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 = ThisWorkbook.Path & "\" ' CurrentProject.Path & "\"
     Set xlapp = CreateObject("Excel.Application")
     Set xlBook = xlapp.Workbooks.Open(ExcelPath & "LibroSoci.xls")
     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, 4) = 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: Because I have this coding in a normal code module, Me. , would error, so I have ' commented that part out.
    ( If I had this coding in a worksheets code module, then Me. would refer to the worksheet of that code module: For example , if the coding were in the first worksheets code module, then these two code lines do the same thing:
    Me.Range("A1").Value = "Hallo"
    Worksheets.Item(1).Range("A1").Value = "Hallo"

    )
    I do not know what Me. does inside ACCESS
    Last edited by Molly Brennholz; 02-07-2020 at 03:46 PM.

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
  •