Thanks for your help. What you sugges is exactly what I tried in order to have the code executed and check whether the excel file was actually opened. So I added
const xlValues as integer = -4163
and also xlApp.visible =true
With these additions, and a breakpoint at the instruction rowNo = etc., the code run, and I was able to check that the excel file was indeed opened, but in ReadOnly mode (this seems to go against what I have read, that workbook.open default is not readonly). However, at this point, the obvious correction seems:
Set xlBook = xlapp.Workbooks.Open(ExcelPath & "LibroSoci.xlsm", ReadOnly = False)
Unfortunately, with this correction I get Compile error, variable not defined for ReadOnly keyword. So I am stuck again.
What seems strange to me is that I have another piece of code in this access project that opens a Word application to print something with mailmerge.
Dim filepath, SQLStmt, WorkbookName As String
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Set WordApp = New Word.Application
filepath = CurrentProject.Path
WorkbookName = CurrentProject.FullName
Debug.Print filepath, NumeroRicevuta
With WordApp
.Visible = True
Set WordDoc = .Documents.Open(filepath & "\StamparicevutaperAccess-2.docx")
End With
SQLStmt = "SELECT * FROM [Ricevute] WHERE [Numero] = " & NumeroRicevuta
'MailMerge selected records from table to Word document
With WordDoc
With .MailMerge
.MainDocumentType = wdFormLetters
.OpenDataSource Name:=WorkbookName, _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="TABLE Ricevute", _
SQLStatement:=SQLStmt, SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
..................................
and this code works fine, so access knows perfectly keywords and enumeration values of the word application.Why not for excel?
Bookmarks