VBA obtaining Dropbox file path for multiple users (Mac and PC) - excel

I created an excel file housed within a specific Dropbox folder that uses a macro to append a date and time stamp to certain tabs of the file and then saves it to that same folder.
On a PC, the path is something like
C:\Users\MyName\Dropbox\Daily History\
while on a MAC it is something like
Macintosh HD: Users: meadowbrook: Documents:
The only thing I can think of to make it dynamic is somehow using CELL("filename") and dynamically storing it as a variable. Is there a way to just save as to the directory the file is in without needing to specify the path in VBA?

Use
Application.ActiveWorkbook.Path
for just the path itself (without the workbook name) or
Application.ActiveWorkbook.FullName
for the path with the workbook name

Related

ThisWorkbook.Saveas not working a second time for all users except myself

I have a new spreadsheet with a macro that saves 2 copies once the data has been updated. Each copy is saved to a slightly different location with a slightly different name. Here's my code:
ThisWorkbook.SaveAs file_full, xlOpenXMLWorkbook
ThisWorkbook.SaveAs arch_full, xlOpenXMLWorkbook
file_full and arch_full are variables with the complete file path and new file name in them like this "G:\Team\Service\Mapping Report\Mapping Report.xls". The difference is the 'arch' one goes to a different folder (an 'Archive' folder in the Mapping Report folder' and has a date appended to the front of the filename.
When I run the code myself, it works perfectly, saving a normal copy and an archive copy with no errors. It's designed to be updated by a few other people but when they run it the get a this error when it tries to save the archive copy:
Method 'SaveAs' of object '_Workbook' failed
I initially thought it was because it was saving an xls copy of an xlsm workbook but it works perfectly for me.
Could there be something in my Excel settings that's making it work for me but no-one else? Is there a better method of saving these copies that would work for more users?

How to open Excel macro files (xlsm) in separate instances of Excel 2016/win10

Does anyone know what registry keys need to be modified in order to open macro enabled excel files in a separate instance of Excel (ie: separate windows)?
I followed the instructions on the following pages Microsoft How-To (if you want to open *.xlsx files in separate instances of excel)
and relation between registry folders and file extensions. The 'Microsoft How-To' link worked nicely and did exactly what it was supposed to do. However, I need xlsm files to open in separate windows and for the xlsx files to continue to open the default way (all in the same window/excel-instance).
I thought if i modified the Excel.SheetMacroEnabled.12\shell\open data (similar to what is described in the first link) the *.xlsm files would then always open in a new window each time.
Instead of this working successfully, now when I try to open an *.xlsm file, a blank excel window comes up with no workbook in it (after this failed attempt I imported the original settigs back so everything was restored).
Figure: I believe one of the folders shown in the image below has the key which needs to be changed in order to open excel macro files in separate windows.
You also need to delete the command REG_MULTI_SZ (the one with the seemingly gibberish-cryptographic value). Backup it in case it goes wrong!
Then, the XLSM files will open in a separate Excel program (notice the brief splash screen, which only appears when a new instance of Excel is created).
But be careful! In my tests, the order in which you open the file types make a big difference!
For example, if there is an Excel instance with a XLSM file open, and you open a XLSX file, it will try to reuse the existing Excel instance, because the registry associated to Excel.Sheet.12 tells it to do it no matter the file type already open. Only XLSM files opened after an existing Excel instance is running will create its own instance of Excel.
I will search for a workaround, but I think this is enough for you to start the tests in your computer.

Store hyperlink of a file using relative path

I have created a hyperlink that connects to the files which exist in the same directory (or subdirectory) as the Excel file. How do I point to the file without setting the full path? The reason I don't want to give the full path is that if I moved the directory which contains other files and the Excel file to a different location, the hyperlinks shouldn't break.
I tried the option below, but the hyperlink only works if I don't move the files.
I want to assign the hyperlink an address like Example\IndexUsage_notes.txt instead of the full path D:\SCRIPTS\ADMIN_SCRIPTS\Example\IndexUsage_notes.txt
After searching online, I found this articles to be useful:
https://www.extendoffice.com/documents/excel/631-excel-file-location.html
This shows you how to get the file path of your workbook and how to isolate the main directory without using Macros.
Then you can insert your main file directory, sub-directory, and filename into the HYPERLINK function.
You can add text to the main directory using TEXT($B$1,0)&TEXT($B$2,0)&......
Dynamic Hyperlink Spreadsheet.png
Once the sub-directories are created and files are in place, you may not be able to move them easily without changing the sub-directory name manually within the spreadsheet or using Macros.

Opening 2 files with the same Name but different directories

I have written a macro which opens 2 comma delimited files (Generic Tables used by Prophet 8.1 ending with a .fac extension), does a comparison and creates another workbook which highlights all the differences.
The macro seems to fail when the files have the same name but has different directories.
What would be the easiest way to overcome this problem without having to actually change the file name as seen in the location? It is against company policy to mess with the actual files as seen in the location. Is there a way to assign some temporary name to the file and not save it?
In Excel you cannot have two files open with the same name!
If you don't want to rename the files, copy one temporarily using a different name - and delete it afterwards (assuming you only want to read from it)
If you have to modify/save the original files, then the only two options you have is to rename them (you can afterwards rename them back to the original name) - or change your procedure so only one file is open at the time (e.g. by temporarily storing some data from the first file in a temp workbook that gets created and closed during the code execution).

How can I create a new Excel 2011 spreadsheet and save it to a particular directory/filename using Applescript

I am trying to write an Applescript program to create a spreadsheet, add data to it, and save the spreadsheet in a particular folder. I have code to create, fill-in, and save the spreadsheet, but I'm not able to specify the folder where the new file is to be saved.
The file is saved in the last folder where I saved a spreadsheet. If I include the full path to the folder where I want it saved("/Users/david/Documents/test/foo.xls"), Excel 2011 creates a file named ":Users:david:Documents:test:foo.xls" in the folder where I had previously manually saved a spreadsheet. So for example, if I manually open Excel and create a spreadsheet and save it in a subfolder of my Documents folder named important, and now run the following script, the file will be created in the important folder, not the test folder.
tell application "Microsoft Excel"
set wb to make new workbook
tell active sheet
-- Lots of code to fill in the data
end tell
set fn to "/Users/david/Documents/test/foo.xls"
save workbook as wb filename fn file format Excel98to2004 file format overwrite yes
close active workbook saving no
end tell
From various posts I've read, it appears one should be able to specify the full path, but the questions usually deal with previous versions of Excel. Also, I'm running Mountain Lion if that makes a difference.
The path type must be HFS instead of posix path.
Use this:
set fn to (posix file "/Users/david/Documents/test/foo.xls") as string
Or:
set fn to "diskName:Users:david:Documents:test:foo.xls"

Resources