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 )
Worksheet: LibroSoci
Row\Col A B C D E 1 2 3xxx 4
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 )
Worksheet: LibroSoci
Row\Col A B C D E 1 2 3xxx 2020 4
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
_._______________
Note: Because I have this coding in a normal code module, Me. , would error, so I have ' commented that part out.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
( 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




Reply With Quote
Bookmarks