0

After processing, my application automatically opens an Excel file. When you open an Excel file, the Save As dialogue box must also be opened. Is it possible ?

using Excel = Microsoft.Office.Interop.Excel;

Save AS Dialoge box calling.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Arif3777
  • 1
  • 1
  • Yes it is ! Please refer to [this link](https://stackoverflow.com/questions/19824123/save-excel-file-using-savefiledialog-class-in-c-sharp) – LiterallyGutsFromBerserk Jun 26 '23 at 13:29
  • You didn't post any code. What you posted isn't even executable code, just a namespace alias. Any method available in VBA is also available through interop. Have you tried actually calling `SaveAs` ? – Panagiotis Kanavos Jun 26 '23 at 13:40

1 Answers1

0

You can use Excel's the Application.FileDialog property (method in C#) to get the required dialog and then display to a user, for example, the following VBA sample shows how to do that:

Sub SaveWorkbook()
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        .Show
        If .SelectedItems.Count > 0 Then
            sPath = .SelectedItems(1)
            ThisWorkbook.SaveAs Filename:=sPath & Application.PathSeparator & "Copy of " & ThisWorkbook.Name
            Cancel = True
        End If
    End With
End Sub

Also you may consider using the .net base class libraries that provide the built-in class for that:

SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"  ;
saveFileDialog1.FilterIndex = 2 ;
saveFileDialog1.RestoreDirectory = true ;
 
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
   string path = saveFileDialog1.FileName;
}

See SaveFileDialog for more information.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45