2016-06-30 14 views
-1

Ich habe ein Makro, die Daten aus einer Word-Datei erhalten und schreibt sie in eine Excel-Datei und speichert sie an einem bestimmten Ort. Ich möchte der Benutzer in der Lage sein zu wählen, wo die Datei gespeichert werden soll.So speichern Sie eine Excel-Datei aus einer Word-Datei und wählen Pfad mit VBA?

Dies ist meine aktuellen 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 

Ich versuchte Application.FileDialog zu verwenden, um den Dialog zu öffnen, den Ort zu wählen, aber ich kann es nicht eine Excel machen Speichern, es öffnet sich ein Word-Datei zu speichern.

Antwort

1

Hier ist ein einfaches Beispiel

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 
Verwandte Themen