Get full path from Save As dialogbx (word/Excel/Powerpoint)

Add-in Express™ Support Service
That's what is more important than anything else

Get full path from Save As dialogbx (word/Excel/Powerpoint)
 
Lakshman Kumar




Posts: 16
Joined: 2019-02-11
Hi,

I had an issue with SaveAs functionality. I want to get the full path of the SaveAs file name, but
1. for Word there is no AfterSave event
2. Excel & Powerpoint had AfterSave event but they are not able to give the full path when saved to PDF as they are using "Publish" method.

Is there any other way to get the full path from SaveAs method whether it is using SaveAs or publish method or anything else?

Currently I am trying to capture "FileSaveAsPdfOrXps" ribbon command, in that event

for Word:

Word.Dialog wordDialog = WordApp.Dialogs[Word.WdWordDialog.wdDialogFileSaveAs];
int dialogResult = wordDialog.Display();
object path = wordDialog.GetType().InvokeMember("Name", System.Reflection.BindingFlags.GetProperty, null, wordDialog, null);

But for Excel and powerpoint, InvokeMember throwing an exception saying "Unknown name".

For Excel am using as below,

Excel.Dialog XlDialog = ExcelApp.Dialogs[Excel.XlBuiltInDialog.xlDialogSaveAs];
bool dialogResult = XlDialog.Show();

For Powerpoint am using as below,

Microsoft.Office.Core.FileDialog pptDialog = PowerPointApp.FileDialog[Microsoft.Office.Core.MsoFileDialogType.msoFileDialogSaveAs];
int dialogResult = pptDialog.Show();

pptDialog.SelectedItems.Item(1) - giving me the full name


For Word/Excel, the above code saving the file automatically, but powerpoint code is not saving it. I think as using FileDialog object, it was not doing so.

Could you please let me know is there any way to get full path for Excel/powerpoint and automatically saves the file to chosen format without writing the code to saveAs (for powerpoint, I tried but SaveAs method not showing the option for Pdf).

Thanks,
Lakshman
Posted 24 Apr, 2019 03:18:38 Top
Dmitry Kostochko


Add-in Express team


Posts: 2841
Joined: 2004-04-05
Hi Lakshman,

Thank you for the detailed description. As you understand, you faced with differences in the Excel, Word and PowerPoint Object Models. Nothing can be done about the AfterSave event missing in Word. As for other issues, you can try to fix them in this way: use the FileDialog object, its SelectedItems collection, and save documents by your own code using the SaveAs methods:
Application.FileDialog property (Excel)
Application.FileDialog property (Word)
Application.FileDialog property (PowerPoint)
FileDialog object (Office)

for powerpoint, I tried but SaveAs method not showing the option for Pdf


In the FileFormat parameter of the SaveAs method, I see the ppSaveAsPDF constant:
Presentation.SaveAs method (PowerPoint)

What version of Primary Interop Assemblies (PIAs) do you use in your project? What minimal Office version shall your add-in support?
Posted 24 Apr, 2019 05:53:28 Top
Lakshman Kumar




Posts: 16
Joined: 2019-02-11
Thanks for the reply Dmitry,

My Add-in needs to support from Office 2007-2019 version and PIAs version is 12.0.6425.1000. But the thing I recently noticed is for example in office 2010 word, FileSaveAs is showing SaveAs dialogbox, where as office 365 pro plus (i think it is 2016 version), it is showing backstage view with FileName textbox & File Format Filters with "Save" button. Once I clicked Save button, then only BeforeSave event being triggered for office 2016.

1. Is there anyway to get the Filename with full path from those controls in BeforeSave event (i.e after clicking "Save" button) without showing msoFileDialogSaveAs dialog box again?
2. Current add-in is not able to get the publish event when saveAs to PDF/XPS, is there any way to intercept that event?
3. I have seen the C# sample for adding menu items on File menu (C# Sample), but when I tried to compile and ran the sample, I couldn't find any menu (either "Publish" or "Share With" menu item in "File" menu), only "Share With" with backstage view was only visible. (I tested in word 2010 & 2016).

Could you please let me know is there anyway to add normal menu item like "Save", so I'll hide existing "SaveAs" & show my own "SaveAs" menu item. (I want to show FileSaveAs dialog directly when user clicks on "SaveAs" without showing backstage view).

Thanks.
Lakshman
Posted 28 Apr, 2019 07:15:52 Top
Andrei Smolin


Add-in Express team


Posts: 16843
Joined: 2006-05-11
Hello Lakshman,

Consider hiding that built-in BackstageView tab to achieve #1 and #2. As to #3, the File menu that example constomizes is the CommandBar-based main menu of pre-Ribbon Office versions; it doesn't and cannot relate to the File tab of the BackstageView.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 29 Apr, 2019 06:46:07 Top
Lakshman Kumar




Posts: 16
Joined: 2019-02-11
Hi Andrei, Thanks for the reply.


1. Even I was able to hide SaveAs backstage view, how could I add, new Item in that place, so I can handle the event for office 2010 - 2019?

2. I pointed out the sample because, in that office 2010 & 2013 was mentioned and I thought the sample will work.

Could you please point me in the direction if possible, so I can add new menu item to File menu for word/excel/powerpoint for office 2010 - 2019?

Thanks.
Lakshman
Posted 29 Apr, 2019 08:32:40 Top
Andrei Smolin


Add-in Express team


Posts: 16843
Joined: 2006-05-11
Hello Lakshman,

Drop an ADXBackstageView onto the add-in module and populate it with a custom tab. As per the Add-in Express manual located in {Add-in Express installation folder}\Docs\adxnet.pdf:

In the code of this sample add-in, you can find how you can customize the Office Button menu in Office 2007, see component named AdxRibbonOfficeMenu1. As to the Backstage View, also known as the File Tab, the sample project provides the AdxBackstageView1 component that implements the customization shown in Figure 3 at Introduction to the Office 2010 Backstage View for Developers . Note that if you customize the Office Button menu only Add-in Express maps your controls to the Backstage View if Office 2010-2019 loads the add-in. If, however, both Office Button menu and File tab are customized at the same time, Add-in Express ignores custom controls you add to the Office Button menu.


The link mentioned above is http://msdn.microsoft.com/en-us/library/ee691833(office.14).aspx.

The manual also points to the sample project above: see the item labelled Add-in Express for Office and .NET sample projects at http://www.add-in-express.com/downloads/adxnet.php.

#2. That project works. I wrote that there's a significant difference between menu File in Ofice 2000-2003 and tab File in Office 2010+: you can't expect that the add-in shows items in these menu and tab with no extra work from your side.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 29 Apr, 2019 09:16:18 Top
Lakshman Kumar




Posts: 16
Joined: 2019-02-11
Thanks for reply,

I am overriding powerpoint SaveAs with my own SaveAs functionality, but I have some issue.

1. Open powerpoint presentation.
2. Edit the file
3. Close the powerpoint (click on 'X' button) without saving.
4. First it triggered "PresentationBeforeClose" event and in that event we are writing the presentation name to log file which is being closed.
5. As file has been modified, it is asking the user confirmation to Save with "YES/NO/CANCEL" options.
6. If user chose "No" no issue, powerpoint application will be closed properly.
7. But if user chose "YES" then PresentationBeforeSave got triggered and in that I sent a message to do Save in that message handler.
6. The Save from that handler again triggering "PresentationBeforeSave" where I had flag to check this is proper event or not and ignoring the event
7. Now the file has been saved (due to presentation.Save()), but powerpoint application has not been closed.
8. Now I have to click on 'X' button to quit the application again.

When I checked without Add-in, there is no issue.

Could you please suggest?

Thanks in Advance.
Lakshman
Posted 14 May, 2019 03:09:17 Top
Andrei Smolin


Add-in Express team


Posts: 16843
Joined: 2006-05-11
Hello Lakshman,

Please check my response at https://www.add-in-express.com/forum/read.php?FID=5&TID=8531.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 14 May, 2019 05:24:35 Top
Lakshman Kumar




Posts: 16
Joined: 2019-02-11
Thanks for the reply.

But I already followed the guide and I had no issues in saving the file when message was sent and also had the flag to ignore 2nd PresentatinBeforeSave event.

Actually I had to issues.

1. Normally once ppt/pptx was SaveAs to another ppt/pptx, then powerpoint will set the newly saved file as current presentation (I think it close source file). But in my case, it was not set, still I can see the old file name in the window title (only sometimes happening).


2. open a file and modify & close it without saving, it will ask for confirmation, click "yes", then I am saving the current file in SendMessage handler. But once the file saved, application is not closing. I need to close again.

Do I need to make any changes to set the current presentation?
Lakshman
Posted 14 May, 2019 19:39:11 Top
Andrei Smolin


Add-in Express team


Posts: 16843
Joined: 2006-05-11
Hello Lakshman,

Lakshman Kumar writes:
Normally once ppt/pptx was SaveAs to another ppt/pptx, then powerpoint will set the newly saved file as current presentation (I think it close source file).


PowerPoint saves the current presentation under a new name and shows the result: the same presentation with the new name. It doesn't close the source file. That is, if you open PresentationA from file, edit it and save as PresentationB, the PresentationA file will be left unchanged, PresentationB will be created or updated, and you'll see "PresentationB" in the PowerPoint window.

Lakshman Kumar writes:
But in my case, it was not set, still I can see the old file name in the window title (only sometimes happening).


Make sure that you do the SaveAs and the new name differs from the original name. Also, pay attention to file time.

Let's solve the first issue first; the second issue may relate to this one.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 15 May, 2019 05:05:46 Top