Link to home
Start Free TrialLog in
Avatar of Foffaf Foffaf
Foffaf FoffafFlag for Indonesia

asked on

VB code to Create Excel file from Outlook 2007 part 5 - Getting email sender name and change the worksheet name

How do you code to get the email sender name?
And change the worksheet name to the email sender name?

Note:
This question is related to these question

VB code to Create Excel file from Outlook 2007 part 4 - https://www.experts-exchange.com/questions/24279935/VB-code-to-Create-Excel-file-from-Outlook-2007-part-4.html?anchorAnswerId=24120589#a24120589

VB code to Create Excel file from Outlook 2007 part 3.1 - https://www.experts-exchange.com/questions/24279744/VB-code-to-Create-Excel-file-from-Outlook-2007-part-3-1.html?anchorAnswerId=24025641#a24025641

VB code to Create Excel file from Outlook 2007 part 3 - https://www.experts-exchange.com/questions/24237135/VB-code-to-Create-Excel-file-from-Outlook-2007-part-3.html?anchorAnswerId=24017516#a24017516
Option Explicit
Sub CreateExcel3(mymail As MailItem)
    Dim objExcel As Object
    Dim objFSO As Object
    Dim objFolder As Object
    Dim sExcelFolderPath As String, sExcelFileName As String
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    sExcelFolderPath = "e:\temp\vba\"   'Folder path
    sExcelFileName = "test.xlsx"        'File name
    Set objExcel = CreateObject("excel.application")
    
    On Error Resume Next
    Set objFolder = objFSO.GetFolder(sExcelFolderPath) 'Set the folder path
    On Error GoTo 0
    If objFolder Is Nothing Then objFSO.createfolder (sExcelFolderPath) 'Create the folder if not present
 
    
    objExcel.Workbooks.Add
    objExcel.DisplayAlerts = False
    objExcel.ActiveWorkbook.SaveAs (sExcelFolderPath & sExcelFileName)
    objExcel.Quit
    objExcel.DisplayAlerts = True
    
    Set objExcel = Nothing
    Set objFSO = Nothing
    Set objFolder = Nothing
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dave
Dave
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Foffaf Foffaf

ASKER

Thx brettdj for your help.

My question continue to:
VB code to Create Excel file from Outlook 2007 part 6 - Getting specific line from email body and put it in the worksheet
https://www.experts-exchange.com/questions/24348084/VB-code-to-Create-Excel-file-from-Outlook-2007-part-6-Getting-specific-line-from-email-body-and-put-it-in-the-worksheet.html