0
Je souhaite parcourir la colonne A à partir de la ligne 3 et debug.print les valeurs de toutes les cellules remplies.Définition d'une variable Excel dans Outlook
Je ne peux pas définir une variable comme plage. Je pense que le problème est que j'utilise Excel VBA dans un IDE VBA Outlook.
Sub Test2()
Dim xlApp As Object
Dim xlWB As Object
Dim xlSheet As Object
Dim enviro As String
Dim strPath As String
enviro = CStr(Environ("USERPROFILE"))
'the path of the workbook
strPath = enviro & "\Documents\test1.xlsx"
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err <> 0 Then
Application.StatusBar = "Please wait while Excel source is opened ... "
Set xlApp = CreateObject("Excel.Application")
bXStarted = True
End If
On Error GoTo 0
'Open the workbook to input the data
Set xlWB = xlApp.Workbooks.Open(strPath)
Set xlSheet = xlWB.Sheets("Sheet1")
' Process the message record
Dim rw As Range
Dim RowCount As Integer
RowCount = 3
For Each rw In xlSheet.Rows
Debug.Print xlSheet.Cells(rw.Row, 1).Value
Exit For
RowCount = RowCount + 1
Next rw
xlWB.Close 1
If bXStarted Then
xlApp.Quit
End If
End Sub
Bonjour, avez-vous ajouté une référence à la bibliothèque Excel? (Dans Outils> Références) Où obtenez-vous l'erreur lors du débogage? – maxhob17
Je pense que j'ai résolu le problème. Je devais dim rw comme Object, pas Range. – NAlexP