OUtlook 2016 Erreur d'éxecution 9 : l'indice n'appartient pas à la selectio
v
Bonjour tous le monde ,
Je suis sous outlook 2016. Et j'ai l'erreur :
Erreur d'éxecution 9 : l'indice n'appartient pas à la selection.
L'erreur est sur la ligne 10 :
Set objExcelWorksheet = objExcelWorkbook.Sheets("Feuill1")
Source du code :
Dim strExcelFile As String
Dim objExcelApp As Excel.Application
Dim objExcelWorkbook As Excel.Workbook
Dim objExcelWorksheet As Excel.Worksheet
Sub ExportFodlerSizetoExcel()
Dim objSourcePST As Outlook.Folder
Dim objFolder As Outlook.Folder
Set objExcelApp = CreateObject("Excel.Application")
Set objExcelWorkbook = objExcelApp.Workbooks.Add
Set objExcelWorksheet = objExcelWorkbook.Sheets("Feuill1")
objExcelWorksheet.Cells(1, 1) = "Folder"
objExcelWorksheet.Cells(1, 2) = "Size"
'Select a source PST file
Set objSourcePST = Outlook.Application.Session.PickFolder
For Each objFolder In objSourcePST.Folders
Call ProcessFolders(objFolder)
Next
'Fit the columns from A to B
objExcelWorksheet.Columns("A:B").AutoFit
strExcelFile = "C:\Users\v.touzot\Documents\PJ\0000000000000000000000000\" & objSourcePST.Name & " Folder Size (" & Format(Now, "yyyy-mm-dd hh-mm-ss") & ").xlsx"
objExcelWorkbook.Close True, strExcelFile
MsgBox "Complete!", vbExclamation
End Sub
Sub ProcessFolders(ByVal objCurrentFolder As Outlook.Folder)
Dim objItem As Object
Dim lCurrentFolderSize As Long
Dim nNextEmptyRow As Integer
objCurrentFolder.Items.SetColumns ("Size")
For Each objItem In objCurrentFolder.Items
lCurrentFolderSize = lCurrentFolderSize + objItem.Size
'Convert byte to kilobyte
'To convert to megabyte, use:
'lCurrentFolderSize = (lCurrentFolderSize / 1024) / 1024
lCurrentFolderSize = lCurrentFolderSize / 1024
Next
nNextEmptyRow = objExcelWorksheet.Range("A" & objExcelWorksheet.Rows.Count).End(xlUp).Row + 1
'Add the values into the columns
objExcelWorksheet.Range("A" & nNextEmptyRow) = objCurrentFolder.FolderPath
objExcelWorksheet.Range("B" & nNextEmptyRow) = lCurrentFolderSize & " KB"
If objCurrentFolder.Folders.Count > 0 Then
For Each objSubfolder In objCurrentFolder.Folders
Call ProcessFolders(objSubfolder)
Next
End If
End Sub
Est ce que quelq'un peut m'apporter son aide?
Merci.
Vincent
Bonjour et bienvenue,
Et si tu essayais avec Feuil1 au lieu de Feuill1 ?
Cdlt.