I'd like to have my spreadsheet behave differently depending on how I call it.
From file explorer I can double click on either "UHF-test.xlsm" or its shortcut, "VHF-test.lnk". From VBA or an Excel formula, how do I determine which one was used?
If I can't determine the link name, is there another way to pass information in the command line, something like this BAT file
start "\B" EXCEL \\qcy-win10-it-2\TDS-repository\TDS-UAXTED.xlsm -VHF
The BAT file solution works fairly well, it's a very small file where I can embed some options for running macros. A small downside is that the Excel PATH is not normally in the system execution PATH and needs to be added.
The goal is toI write and maintain one only macro-enabled spreadsheet stored in a network location but with the ability to allow multiple users to use it with different products and parameters without being prompted by a macro on startup.
I still prefer determining the shortcut name if someone has that solution.
Related
I have written some code in Excel VBA which calls a macro in another workbook. The other workbook's VBA code is locked, but I can still run the macro itself. The macro does some calculations, then brings up a dialog box so the user can choose where to save the results.
After running this macro, I need the file path for the results file (to use the results in further calculations).
Is there any way to store the file path chosen by the user? Or alternatively, is there any way of automatically putting a specific file path in the dialog box to save to?
You can not get the file path directly. One workaround could be to use Application.RecentFiles(Application.RecentFiles(i).Path/Application.RecentFiles(i).Name). Unfortunately I don't have excel installed on my PC is I can't test if it really works.
If this workaround don't work, that there is no other way to get the file path. You would have to ask the user to select the file.
I have about 10000 excel files, that in a specific cell of all of them there is a picture. I need a script to read all files and save the picture with the same name of the excel files in a folder.
Could you please help with that?
Thanks.
This method is based on a number of assumptions:
All the files (10000) are located in a know folder,
All files are named according to a paradigm that can be reproduced programmatically (if not, you can get the list of files within the folder, store the list within an array, and loop through the array),
Pictures are always within the same worksheet or, if in more than one, the names of the worksheets can be reproduced programmatically,
The filenames to be used to save the pictures can match (at least as a seed) the one of the Excel the pictures are extracted,
You will manage to write some basic VBA.
Note that for the VBA you have at least two options:
Write it within an EXCEL that will only serve as the extraction engine, or
Write it as a stand-alone file and run it via DOS commands.
The VBA logic:
Create the outer loop that processes a single file,
Within the outer loop, generate the name of a file to be open,
Open the file using Workbooks.Open VBA function,
Select the worksheet and the cell containing the picture,
Use the Workbook.SaveAs to save the picture (you will need to specify the type of file to be used, e.g. .bmp).
As a simple and very efficient tool to get the code (at least) partially generated by Excel, you can RECORD a MACRO for each action and then stop recording. You will see the code generated (you will need to access the VBA mode). You can copy-paste the generated code into your development (you might need to do some simple adaptations though).
That's it.
Hope you manage. Good luck!!
I am trying to develop a manner in VBA to track changes in a document without having to hide the contents in an extra sheet within a workbook.
I understand that if you change the extension of an Excel file to ".zip", you can access the Excel document as components sorted into directories. Is there a way to save and write to a text file within one of these directories so that I can access it every time the document is opened, without having to have the user drag a log file along with the Excel document?
Some facts:
When Excel opens the file, the file is blocked by Excel. There is no possibility to write to that file within VBA
You can store additional data into that file externally or after the Excel workbook has been closed
You would need to have code externally from the workbook to accomplish writing to that file after it has been closed. You may want to use VSTO or an oldschool Excel Addin.
you have to ensure that Excel will not destroy your changes when restructuring or repairing the file.
In the first run, your idea sounds very natural, to not use sheets from a programmer's point of view. You only have full control on Excel files when
you use external libraries (e.g. Spreadsheet Gear) or
you remote control Excel via automation.
you use openxml SDK for Excel
you use VBA
You could insert additonal information and take care that this information is not skipped by Excel.
When you want to do the tracking this way, I would suggest you to use an Excel Addin. There is actually no need for installation when using this kind of Addin. Attach to open workbook and close workbook events and ensure that all changes are written to the Excel Workbook after it has been closed. Certainly you would have to attach to all kind of other events to track all changes to the workbook. You may need to have in mind that there can be more than one workbook opened at a time.
Actually there are alternatives.
write your logging code in VBA or whatever fits
abstract away how your persist the code (e.g. use a data provider)
think about these two alternatives to store logging data:
You can save logging data in cells of excel. When using a "newer" version of excel, you have a limit of 1 million rows. You may want to implement a rolling mechanism that ensures that you never go over the border of 1 million records. (you may be dont want to track a million changes)
You can use the document properties to store you information as xml.
Last but not least, the most obvious: Why not using Excel's functionality of tracking changes? Understand track changes in Excel 2013
I'm using Excel 2010 and adding a small VBA macro to a spreadsheet. (The purpose of the macro is to take the data on the active sheet and export it to a CSV file, but that's tangential to the question.) The macro determines the output path for the file using ThisWorkbook.Path. I also added a custom button to the Quick Access Toolbar to activate the macro.
After getting a working algorithm in place in my experimental spreadsheet (Test.xlsm, stored in one path), I made a copy of the spreadsheet in another path and renamed it to _Database.xlsm. Then I opened _Database.xlsm and ran the macro. To my surprise, the file was written to the original path, not the new one. And looking down at the Windows toolbar, I saw that Excel had opened the original file over in its original path as well.
After a lot of jiggering around with code tweaks, checking properties and such I finally found that I could prevent this by opening the copied spreadsheet, removing the Quick Access Toolbar button, re-adding it, and then saving the file. My questions are:
Why isn't the macro "independently portable" along with the spreadsheet? I.e. why does the copy maintain this kind of tie to the original sheet?
Is there a way I can create or modify the macro to make it portable in that sense?
If you want a toolbar/button to travel with a file (ie. not always link back to the original version) then you need to add it to the file itself, not to the QAT. The QAT only "knows" about the actual file you linked the button to.
It might be better to add the macro to your Personal Macro Workbook and then just have it operate on the ActiveWorkbook.
However, if you want to distribute it to other users, you can keep the macro in the "database" workbook and add a custom ribbon part. See: http://www.rondebruin.nl/win/s2/win001.htm
We're having a problem with the Insert Hyperlink problem taking forever to populate because of a ton of files in a network folder (Windows 7, xp was fine... oh the good old days. And yes, I've tried everything, disabling search, different reg entries, etc... and I'd like a different and less hacky solution.)
What I'm looking for is a macro that prompts for a number (in this case a client file number), and then opens the Insert Hyperlink dialogue inside a specific folder (for example, the file number the user enters might be 4321, and then the insert hyperlink dialogue would be opened inside the folder z:\clients\4321\ It's the z:\clients folder that has a stupid number of folders in it)
The actual file that would be hyperlinked would be somewhere inside there, so additional browsing would have to be done by the user. And I'm not sure exactly how the macro would behave in so far as knowing what to hyperlink (presumably the current cell would make sense to me).
Thanks for any help you can provide!
... You may have to play around with it a bit, but your best bet is probably to set the Hyperlink Base for each user's sheet and then set relative hyperlinks in the sheet itself.
Hope this helps...