0

I have a macro that get data from a word file and writes it into an excel file and saves it to a specific location. I want the user to be able to choose where to save the file.

This is my current code:

 Sub createExcelFile()
        Dim mPathSave As String
        Dim xlsApp As Excel.Application
        Dim xlsWB As Workbook

        Set xlsApp = CreateObject("Excel.Application")
        Set xlsWB = xlsApp.Workbooks.Add

        'Want to make it dynamic'
        mPathSave = "C:\temp"

        callFunc = createExcel.createExcel(xlsApp, xlsWB)

        'Save the excel file
        xlsWB.SaveAs mPathSave & "\" & "teste" & ".xls", FileFormat:=56
        xlsWB.Close
        xlsApp.Quit
        MsgBox "Novo arquivo salvo em: " & mPathSave & "\" & "teste" & ".xls", vbInformation
    End Sub

I tried to use Application.FileDialog to open the dialog to choose the place, but I can't make it save a excel, it opens to save a word file.

1 Answer 1

1

Here is a simple example

Sub createExcelFile()
    Dim mPathSave As String
    Dim xlsApp As Excel.Application
    Dim xlsWB As Workbook

    Set xlsApp = CreateObject("Excel.Application")
    xlsApp.Visible = True
    Set xlsWB = xlsApp.Workbooks.Add

    'Want to make it dynamic'
    Application.FileDialog(msoFileDialogFolderPicker).Show
    mPathSave = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)

    'Save the excel file
    xlsWB.SaveAs mPathSave & "\" & "teste" & ".xls", FileFormat:=56
    xlsWB.Close
    xlsApp.Quit
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

May want to set xlsApp.Visible = False right before show dialog so Excel is minimized because dialog may be under Excel window.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.