How can I get the file name from the "Save As" input box (NOT the file dialog) prior to saving? - excel

I am trying to do some validation on the file name before it's saved.
Here are my three file-saving scenarios:
File > Save
File > Save As > Browse > Save
File > Save As > Save
Additional Info:
As defined in the Workbook_BeforeSave event, the SaveAsUI parameter will indicate whether or not a dialog box is needed to save changes.
✓ In scenario 1, SaveAsUI=False, so I get the filename from ThisWorkbook.Name
✓ In scenario 2, SaveAsUI=True, so I force a dialog and get the file name with the GetSaveAsFilename method
✗ In scenario 3, SaveAsUI=True, but no intermediary dialog is ever actually required! The file gets immediately saved to that name entered in the input box.
...it's ridiculous that I'm obsessing over this because I can just override scenario 3 and force a dialog anyways, but I'm curious. Any ideas?

I'm writing this as an answer, because the comment field is too small for it.
I found the mentioned file reference in the registry:
HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Excel\User MRU\AD_2B763A186A5179F1E2C2819B76BF6FDEF3F399938D48925BE3381441F2190369\File MRU
You'll need a find, either to open the Recent file list, or to find a way to read such a registry entry. One way (but quite a complicated one), the Shell command, as you can see here (commandline command):
reg query "HKCU\Software\Microsoft\Office\16.0\Excel\User MRU" /s
Launching this command and parsing the results might help you.

I found what was missing in our missing vocabulary: Built-In Dialog Box
As explained here, there is no way to get the file name from this dialog until after the save has been made.

Related

Hyperlink in Task Dialog footer to CHM? [duplicate]

I have created a .CHM file and then when I open it in c# I get the First topic. I want to open it to a specified topic.
This is the code I use right now to open it.
Help.ShowHelp(this, "./Resources/ServerHelp.chm");
I want to be able to open it to a specific topic like Audio. I tried using
Help.ShowHelp(this, "./Resources/ServerHelp.chm", HelpNavigator.Topic, "Audio");
and it showed me page not found. Can i get some Help with my Help please !! :P
This can be achieved by the following steps:
Identify what names the chm uses to refer the internal topics. This is done by
Open the CHM file, and right click in the topic page and select Properties.
The property called: Address (URL) Contains the topic page name at its end.
Here is an example:
mk:#MSITStore:C:\Program%20Files\Silsila%2011\Silsila.chm::/Audio.htm
Here the topic page name is "Audio.htm"
Call the Help.ShowHelp() function with the correct parameters as shown below
Help.ShowHelp(this, "./Resources/Silsila.chm", HelpNavigator.Topic, "Audio.htm");
That should do it. you can fine the topic name of the pages you want using Step 1, and then use Step 2 to open the help file on that page.
The same also works to create a windows shortcut opening a specific page. Use that as "target" command line :
C:\Windows\hh.exe ms-its:[file_name.chm]::[page_name.htm]
If you do not know [page_name]: from the chm help viewer, try to print the target page on a virtual printer like PdfCreator. The output filename automaticaly generated will probably contain [page_mane].
With thanks to sazr for the intial syntax !

Check share point if file exists in a shared document folder with power automate

I am trying to get the attachments of some emails and check if that attachment already exists in SharePoint. However, since the flow may have already run over some attachments that have already been received, they may or may not already be in SharePoint, so I first have to check SharePoint if the attachment exists and if they don't, create the file using the email attachment content.
So what I have so far is replicating a process that was described here
The problem that quickly arises is that under "Get file content using path" action, the File Path input box(circled below) won't let me append a file path that isn't currently already in a document folder.
Not sure if this is still a valid way to accomplish it or if there's another way. I have checked all over the place and still haven't been able to find a solution. If there's anybody that can help it would be greatly appreciated!!
To tackle this what you can do is to create a variable using Initialize variable action and compose the path e.g. '/DocumentLibrary/file.ext' that you want to check if exists. then you can refer to that variable in your folder path box for Get file content using path action. Please see the screenshot:
Next you can configure run afterfor file creation action and create file if Get file content using path action has failed, otherwise do other stuff that is required. I have tested this for sending different emails based upon file found or not found and it works well.
Hope this solves your issue.

select and copy files + directory [duplicate]

I am using Tkinter for building a GUI for a python script. I need a button which opens up a dialog box which allows me to select both files and directories.
Till now, I've come across
tkFileDialog.askdirectory(parent=root, title=dirtext1)
which allows just to select directories in the dialog box
and,
tkFileDialog.askopenfilename(parent=root, title=filetext)
which allows me to just select files. As of now, I access these dialog boxes using separate buttons, each of which calls one of these functions.
Is there anyway to select either a file or a folder using a single dialog box?
I don't think so. There is no built-in class to do it easily
Investigation
If you look at the tkFileDialog module's source code, both the Open and the Directory classes inherit from _Dialog, located in tkCommonDialog.
Good so far; these classes are simple and only extend two methods. _fixresult is a hook that filters based on your options (promising), and _fixoptions adds the right tcl parameters (like initial directory).
But when we get to the Dialog class (parent of _Dialog), we see that it calls a tcl command by a given name. The names built-in are "tk_getOpenFile" and "tk_chooseDirectory". We don't have a lot of python-level freedom of the command after this. If we go to see what other tcl scripts are avaliable, we are disappointed.
Looks like your options are
ttk::getOpenFile
ttk::getSaveFile
ttk::chooseDirectory
ttk::getAppendFile
Conclusion
Rats! Luckily, it should be quite easy for you to make your own dialog using listboxes, entry fields, button, (and other tk-builtins), and the os module.
Simple Alternative
From your comments, it looks like a viable simple work-around might be to use
directory = os.path.dirname(os.path.realpath(tkFileDialog.askopenfilename()))
They'll have to select a file, but the "Open" button will "return a path", in the sense that the path is computed from the file location
But I really want it!
If for some reason you really want this behaviour but don't want to remake the widget, you can call tcl scripts directly. It may be possible to copy the code from getOpenFile and provide more loose arguments that allow for selecting a more generic object. This isn't my speciality and seems like a really bad idea, but here is how you call tcl directly and here is where you can learn more about the underlying commands.
I've had a similar issue.
In the end, I used askopenfilenames() (plural) and split the path from the files. Then with a radiobutton, ask the user to choose if they want to process all the files in the directory, or just those they selected.
filetypes = [('All files', '*.*'), ('CSV files', '*.csv'),]
data_list = askopenfilenames(title='Select folder', filetypes=filetypes)
data_dir = data_list[0].rsplit('/', 1)[0]
I mention it because askopenfilenames() doesn't get suggested much, but is closer to selecting a folder, as can ctrl+A all files.

Make Infragistics UltraGrid Document Exporter launch file

We have an existing application that allows exporting of an Infragistics data grid to either Excel or PDF format. Currently, when the user clicks on the Export button, it asks them where to save the file and then it exports it and saves it. Then, to launch it, they go to where they saved it and then it launches.
The user wants the application to instead launch the grid into either Adobe Acrobat or Excel and THEN that is where the user can opt to save the file. They don't want it to ask where you wish to save it before it exports, like it currently is doing now.
Is this possible with the Infragistics Document Exporter? I couldn't find any information on this from the Infragistics web site.
I'm thinking, instead of giving it a filename, I could instead use a stream maybe to the console or something like that and let the OS give the user the option to launch it?
Is there an example somewhere of this being done? I see there is an overload in the Export member function that allows you to pass in a stream.
Thanks!.
The Infragistics excel engine and documents engine will need to write to a file to be able to have the file opened in Excel or Adobe Acrobat so you will still need to save a file before they can open it.
For the requirement to open the file, you could use System.Diagnostics.Process.Start method and if there is a program associated with the file type you can pass the file that you just saved.
As there is a dependency on the file system to open the file in Excel or Adobe Acrobat you will not be able to achieve your goal of not requiring the file be saved first. While it may be an option to save the file in a temporary location and then open that file it also has an issue that if the user were to click save in excel it would still save in the temporary location so they would need to know to use Save As to save in a different location.

Applescript to capture result of close dialog

How does one capture a "Don't Save" or "Save" response to the Standard Suite "close" dialog?
try
close front document saving ask
on error
return
end try
returns "error number -10000" if the user selects "Cancel", so that case is handled.
However, subsequent code depends on whether "Don't Save" or "Save" was selected.
Thanks
UPDATE
Using regulus's answer and it's workaround strategy, I prefaced the code above with
tell application "Finder" to set _modDateAfterSaveDialog to
modification date of (info for file _filename)
where the _filename was assigned earlier from application-specific AS code.
Analogous code and a test followed the "try".
I really have no idea how to get it directly. I assume the command you are issuing is a specific application command, not a standard suite command because standard applescript doesn't have a "front document".
In any case, here's a work-around idea that might work. When a file is saved its modification date changes. So you need to know the file of the front document. Then you just check the modification date of the file before and after you issue this command. If it changed then you know the file was saved.
Good luck.

Resources