I am trying to see if there is a shortcut to quicken my workflow.
I have a workbook I have created that runs analyses of given scenarios, and I make a lot of reports that are basically just printouts of a whole bunch of those analyses.
Right now, the workbook is set up to just print out the results by grabbing the two relevant print areas from the two relevant worksheets, and then exporting via the Sheets.Printout Function.
That is reasonably efficient, but when I print dozens of them, it gets a little annoying to type out the full filename (which needs to reference several properties for each one).
I want to set a default filename that just grabs the data from a couple cells and sets that as the name, but I'd like it if that filename populated the entry in the save as window for printing to a pdf, rather than saving to that filename with no input because
I don't always want to use that file name and
I'm worried about forgetting to update the cell entries in the worksheet, and accidentally overwriting old files without noticing.
For example, if I just go through the normal interface and tell excel to "save as", that window pops up with the existing filename already in that interface as a "suggested" filename.
Is there any way to do that with a filename that is derived from values in the worksheet?
Currently, whenever I use the sheets.printout function, the filename entry defaults to a blank value
Related
I use VBA in Excel to pull data from different sources (mostly .csv and .xls/.xlsx files) and paste them into my data tables (in the same Excel File I have a data table for each specific data source).
Each of those files comes with different settings. I have created an specific VBA Macro for each of my data sources to process, remove and copy the relevant information of each individual file, and then I call all of the Macros from another Macro. The problem I'm having is that for one of the data sources, when using the Workbooks.Open method, I have had to set the parameter Format to "Nothing" (Format:=5). But this affects then the subsequent macros and therefore the following files are not processed correctly.
I know I have two possibilities: Either I call this macro at the end, after I've processed all the other files or; I set the Format parameter in all of my Macros to the one specific for each of the files configuration. However there must be a way to simply reset the delimiter to the default one used in my Regional Settings. Does anyone knows a solution?
Sorry if there's already a thread with this issue but I've tried looking for it and didn't find any.
Thank you in advance.
my question is a pre-code question, as I would like to verify if and which is the best option to go about this - either formula, VBA or not possible.
I have a main workbook with an array of codes inside cells in sheet 1 - all in the format HXXX-XXX-XXX where X is numbers ranging from 0-9. Each code has an associated revision number as shown in the attached picture.
The workbook itself is named in the format: 'HXXX-XXX-XXX-YY Example Title' where YY can be any number starting from 0 to infinity (in theory). Only YY is subject to updates in the title. If changes are made in this workbook, then a new version is saved, with the YY changing in the title to the next consecutive number - Nothing else changes.
From this main workbook there are a large number of other workbooks (around 50) which share the same codes and revisions. My goal is to link all these workbooks up so that I only have to update a core main workbook and the rest of the codes (HXXX-XXX-XXX) revisions in all the other linked workbooks update accordingly.
The problem is that the other linked workbooks have a dynamic name in the format: 'HXXX-XXX-XXX-YY Example Title 2' where YY can be any number starting from 0 to infinity. YY gets updated to the next consecutive number if a change is made inside the document and this document is then saved as a separate document using Save As. NOTE: not all workbooks will get updated at the same time, as it all depends on which codes and therefore revisions are changing.
My question is firstly, is this possible with current excel functions to update links with ever-changing workbook links, which are saved as different files each time in the same folder?
Secondly, I have read about the INDIRECT function, but it is limited only to having the required workbooks opened at the same time as the updates to the main workbook, hence I am unsure that Formulas will work (I will be linking 50 workbooks to the main workbook) - From this I am gauging that VBA may be the best option, but I would like to double check this is possible before I begin attempting the code.
Of course the use of Formulas in the sheets would be much better, but because the file names are dynamic, and since the updated workbooks are saved as different files each time changes are made to it, I don't believe this is possible.
If I understand your problem correctly you need to differentiate between 3 things.
Using only Excel Formulas.
The problem with this is that formulas crossing workbooks have the big disadvantage, that you need to have the source-workbook open, otherwise manny formulas will not work correctly or update. You also have the disadvantage that saving the file needs still to be done automatically. The advantage is that you do not need VBA macros.
Using Power Query
With Power Query youmight be able to solve the problems with the dynamic names.You can even read a whole folder of files, combine them and do transformations without the need to open the files manually. But you still need to save new files manually and the files will only update once they are opened.
Using VBA
You can prettymuch do everything you asked in your problem description but VBA has its own disadvantages. Firstly the file-format ".xlsm" is not allowed by the IT department everywhere. Also to work, every user using the files needs to activate macros, otherwise the macros won't get executed. Therefore I think a VBA solution is better fitted if you only have a small circle of users or if you can execute the macros on your own (e.g. if the main workbook was updated, you need to execute a macro which opens, modifies and saves all affected files). After that you colleagues do not need VBA themself.
Possible solution:
To avoid VBA you could try to create a Power Query in each "other workbook". The query will read all filenames in the folder where the main workbook is located. Now you sort and filter for the workbook with the newest/highest ID/Titel automatically and load the result as an seperate Excel sheet (all that is possible with power query and without VBA).
Now you can use the "indirect" formula to use the ID/Titel to link to the newest main workbook. As mentioned above this will require that the main workbook is opened. Otherwise the indirect formula will not update the values. If that is out of the question, you probably need to go with VBA.
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'm currently writing a conversion function that takes data and creates an .xls file where part of the data becomes the sheet names.
My problem is, xlswrite automatically creates 3 default sheets with default names when it creates a new Excel file. Of course, these usually don't match the names in my data, so after my conversion is done, my Excel file looks almost fine, it simply has 3 leading sheets which are not supposed to be there.
Is there a way, without using ActiveX, to either stop xlswrite from creating those sheets in the first place, or delete them afterwards?
I just found out xlswrite actually uses AxtiveX internally, so the answer is
No, there is no way.
Just use ActiveX.
I made a copy of a template Excel file with a single named sheet from the program directory to the current directory, and then write to this file.
Use
fileparts(mfilename('fullpath'))
to get the path to the program file.
I have a spreadsheet where I can enter a reference number and Excel generates a table based on the data tied to that reference number.
Rather than enter each reference number individually and copy the resulting table manually, is it possible to automatically iterate the process of entering the reference numbers (from an existing list) and exporting the results separately?
My Idea:
I didn't quite understand HOW you need to automatically enter those reference, but a good idea would be writing all the numbers you need in a .txt file, then program a button which loads a msoFileDialogFilePicker to select your file. When the file is selected, you can open it with a New FileSystemObject, read it with ReadLine and filling an array with all the numbers you have written in the .txt file. Then with a forcycle from LBoundto UBoundof that array you can enter those numbers automatically in your Range.
To export everytime your results table (which again I didn't quite understand HOW you want it to be exported), an idea would be a Worksheet Changeevent (if the results table appear in your spreadsheet) in which you can write down some code to copy-paste the results table in a new worksheet and then save it, or make a .pdf of the results table from its area.
The possibilities are really too many to write a single piece of code to show you :)