Excel VBA: Setting a Workbook-level default save directory - excel

I want my workbook to have a default save directory, e.g. "n:\mydirectory\hello", So each time I open it and try to save it, it will suggest this directory regardless of which other Workbooks I have saved in other paths recently.

Using the Workbook_Activate event, you can change the "current directory" with the ChDir statement so that whenever you are working within this file, the default save directory will be changed to what you want.
Note: this will only help for new files that have not yet been saved; existing files, even if you do a Save-As will default to their own directory.

If the issue is specific to a single workbook (say, a template you regularly fill out and save as another filename), you could write a macro in that workbook to perform the Save As operation into the same folder (or some other static folder) using either a dialog or data from the spreadsheet to determine the new filename.
If the issue is that you just don't like saving files to "My Documents" by default, you can change Excel's default save location across the board. This setting is in the options (the exact location depends on which Excel version you're using).

Related

How to make self-modify Excel workbook in shared folder with read-only permissions?

I made a workbook with VBA which is stored at shared folder of my employer. Employees can open this folder and workbook, but only as read-only.
User at this workbook works with several macros and I need to count number of starts these macros and store this data somewhere. In the best way, it will be stored in the workbook itself. But they do not have rights to modify the workbook, so they cannot save it even if I will try do it automatically as part of macro.
So what I need, is to find a way, how to make this workbook self editing (or auto-saving).
I found two possible ways, but they do not work at this scenario:
Because the file is opened just in read-only mode, I cannot save it directly. I even cannot use save-as and rewrite that file, because I haven't rights to editing it in that folder.
I found a way, where is new document in PC repository and the workbook saves data in that file and this file must be saved somewhere, where it could be editable. But I do not know networking enough to find a save place where I will make this file and even more, I am not sure, how will HQ looks at this type of activity.
I would prefer to count it in the file, but from MS support I get, that I cannot save it, just rewrite, which is impossible if I have not rights for that. So my question is, is there any save way how to count it or store data somewhere else?
As far as I know, without getting write-permissions fixed for your users, it can't be done. You should work with your network administrator to explain your requirements for the users.
Alternatively, you need to find a place where every user DOES have write-access, then design the script to save-as to that location. It all comes down to permissions.

Need to monitor user downloads folder for new .xlsx files, then open Excel, save the file, and close Excel

At work I use a tool that requires me to download a .xlsx file, open it, then save it to remove the workbook protection. I'd like to create a script that automatically opens and saves any .xlsx files that are saved in the downloads folder.
I'm assuming PowerShell is the right tool to use. I found this article that explains how to do something similar, but I need help with configuring the parameters.
https://social.technet.microsoft.com/Forums/scriptcenter/en-US/1faa97e0-2288-4bb2-b8ad-283df32779d4/can-i-open-an-excel-workbook-when-files-with-a-certain-extension-are-saved-in-a-specified-folder?forum=ITCG
What I need is for the script to monitor the $env:USERPROFILE\downloads folder for any .xlsx files. Then I need it to open that file in Excel (preferably in a minimized window), save it with the same filename, then close Excel.
You can use IO.FileSystemWatcher to monitor a directory. See Start-FileSystemWatcher for an example implementation in PowerShell.

External Links not auto-updating when Source File is OPEN

I have a very odd occurrence happening. Linked data in a Master workbook is not updating when one of its source files are open. I have a Master workbook that has links to about two-dozen source workbooks. The links work properly when I open the Master file. However, if I open both the Master workbook and one of the source files and proceed to change one of the inputs from the source file, the update does not flow through to the Master file.
If I then save the source file and click Edit Links >> Update Values in the Connections section of the Data tab of the Master workbook, the data updates. I don't want to have to perform this manual "push" every time I update the source.
The only symptom I can find is that the reference to the source file in the Master file does not become an internal reference when the source workbook is open. It retains the entire file path (i.e. 'C:\shared\username\folder[filename.xlsm]sourcedata'!$D$3) instead of simply beginning with the bracketed expression ([filename.xlsm]sourcedata!$D$3).
Using Excel 2013.
This is only happening on my machine. I tried it on two other machines and the links work properly.
I have checked my calculation settings to automatic, and have Trust-Center set to the most permissive setting possible. I have automatic updating of links turned on. This workbook is password protected for EDITING (it can be viewed without a password).
Please help!!
This sounds like an issue I once had, I suggest you to try changing the file path syntax to UNC convention, i.e. instead of C:\shared\username\folder[filename.xlsm]sourcedata'!$D$3 something like: \\\ComputerName\C$\shared\username\folder[filename.xlsm]sourcedata'!$D$3
That sometimes helps

Recover unsaved .csv file changes

Does anyone know a way to recover changes made in a .csv that were not saved when excel 2007 was closed.
At the moment, I don't see any way to solve this.
Check all the temporary files created recently. Especially alongside the file you opened. There are a few temp folders in the system that Excel may use. C:\Windows\temp is the main one, but it is usually under the Users folder in later versions of windows. Eg: C:\Users\YourUserName\Local Settings\Temp
If you find any files that look like Excel temps, take a copy and rename the extension and then try to open it.
(Your only real chance is if auto-save kicked in and saved a copy - to a temp file - when you still had your new changes in the document. Otherwise the changes are lost I'm afraid)
If option #1 doesn't resolve your problem in Excel, go to File->Options->Save. Hopefully your AutoRecover file location, under the third box, will be populated with an address.

Matlab: open files 'outside Matlab' by default

I'm looking for a way to have Excel files in my Matlab folder open 'outside Matlab' (i.e., by MS Excel in most cases) directly by double-clicking the file, rather than right-clicking and selecting 'Open Outside Matlab'.
The .xls files reader built in Matlab can be terribly slow for large files, and an unwanted double-click on a file can cost quite some time in which Matlab is unresponsive.
Thanks.
When you click something in the Current Folder tab, it's actually running the open command, which itself calls finfo to determine what it means by "open" for a given extension. You can see this by creating a breakpoint in open.m directly after the line [~, openAction] = finfo(fullpath); and double clicking - when it hits the breakpoint you'll see it returns openAction as uiimport.
In theory, you can create custom methods for extensions by creating on the path a function openabc where abc is the extension, which should be returned as the openAction.
However, if I look at my finfo.m it first searches for said functions and then regardless of whether or not it finds them if there is an inbuilt method it overwrites them with the standard behaviour. There's even a comment:
% this setup will not allow users to override the default EXTread behavior
If you are willing to muck about in the inbuilts, you may be able to do it like this (backup first! - this could affect other things). I did it temporarily by shadowing the existing finfo like this:
edit finfo.m (Now save a copy to the current folder)
Add these lines after the loop that defines the openAction (in my version, around line 85):
if any(strcmp(['.' ext], matlab.io.internal.xlsreadSupportedExtensions))
openAction = 'winopen';
end
From the folder containing your edited finfo.m, type which finfo -all. You should see two copies, the MATLAB one labelled as shadowed. Opening something from the current folder window should now open Excel externally.
I don't believe there's any straightforward way to do that. It's built in to MATLAB that Excel files will open in the import tool when you double click on them, and there's no way to change that.
You might be able to get around it by changing the file extension on your Excel files to something other than .xls or .xlsx. That would stop MATLAB from opening it in the import tool. Then in Windows, you could associate the new file extension with Excel.

Resources