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 3.1

When I changed the path c:\deleteme\test.xlsx to c:\deleteme\vba\test.xlsx my code asks "Do you want to save the changes you made to test.xlsx?", what happened?
Its seems like the code only capable to create 1 level folder olny.

But the code from part 2 of my question, the one with a function, using the same path its working fine for any levels. Could you please explain in more detail and what should I change in the code so it'll be able to create any level of folders without function?

Thx.

Note:
This question is related to these question

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

VB code to Create Excel file from Outlook 2007 part 2 - https://www.experts-exchange.com/questions/24163884/VB-code-to-Create-Excel-file-from-Outlook-2007-part-2.html?anchorAnswerId=23699562#a23699562

VB code to Create Excel file from Outlook 2007 part 1 - https://www.experts-exchange.com/questions/24139919/VB-code-to-Create-Excel-file-from-Outlook-2007.html
Sub CreateExcel2()
    Dim objExcel As Object
    Dim sExcelFilePath As String
    Dim objFSO As Object
    Dim objFolder As Object
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    sExcelFilePath = "c:\deleteme\test.xlsx"
    Set objExcel = CreateObject("excel.application")
    
    On Error Resume Next
    
    Set objFolder = objFSO.GetFolder(objFSO.GetParentFolderName(sExcelFilePath))
    
    On Error Resume Next
    
    If TypeName(objFolder) Then
        Set objFolder = objFSO.CreateFolder(objFSO.GetParentFolderName(sExcelFilePath))
    End If
    
    objExcel.Workbooks.Add
    objExcel.ActiveWorkbook.SaveAs sExcelFilePath
    objexcel.quit
    
    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

brettdj,

Why do you need to suppress the Alert on the SaveAs?

In case you are overwriting an existing file (ie if you rerun the code with the same paths)
If the file is being created from scratch then you will not get this message
This i suspect if why you had the "Do you want to save the changes you made to test.xlsx?" message
Cheers
Dave
Thx brettdj, your codes working as I need.
I'll post another question related to this question, please assist me.
 Continuing question in:

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