Working outlook via vba code with xlsx - error

Joined
Jul 18, 2023
Messages
1
Reaction score
0
Haloo ! I am writing in outlook 2007 macro what si working with xlsx. In some row ic code is error

Sub WriteToExcelFile()

Dim xlApp As Object
Dim xlWorkbook As Object
Dim xlWorksheet As Object
Dim filePath As String

On Error Resume Next 'firstly, try catching the existing open session, if any:
Set xlApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then 'if no any existing session, create a new one:
Err.Clear: Set xlApp = CreateObject("Excel.Application")
MsgBox "Object created"
End If
On Error GoTo 0

' Set the file path of the Excel file
filePath = "c:\moje_dokumenty\E-Recept\data.xlsx"

' Create a new instance of Excel
' Open the Excel file

'On row is mistake "call was reejected calee"
Set xlWorkbook = xlApp.Workbooks.Open(filePath)

'other code write with sheet in c:\moje_dokumenty\E-Recept\data.xlsx

' Check if the file exists
If Dir(filePath) <> "" Then
MsgBox "The file exists."
Else
MsgBox "The file does not exist."
End If
.

End sub
'Version Office 2007
'References in Outlook and Excel Visual basic Application:
'Microsoft Office Excel 12.Object Library
'Microsoft Excel 12.Object Library

How can I solve my problem ? Thanks for help !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top