Is it possible to save table data into another macro? - excel

Does macro programming allow to read data from a table and hardcode it into another macro?
Situation is that I want to read all data from a worksheet with a macro. I then want to save that data without the help of an additional program to another macro so I can delete the table, restart my pc and still be able to retrieve all data from my macro.

You can "create a macro through a macro" (OPs words) through the VBIDE.
To so so, add a reference to Microsoft Visual Basic for Applications Extensibility. You can then write code to read and write to your VBA application. You will also need to set Trust access to the VBA project object model in the trust Center.
That said, there may be better ways to achieve what you want, eg
Hide the sheet using xlSheetVeryHidden so it's only accessable from VBA
Write the data to one or more hidden Names
If you are using .xlsm, these documents can also contain custom XML parts, which you can use to store arbitrary XML data in the documents. MSDN refrence: Custom Xml Part

Related

Amending a text file in Sharepoint via Excel VBA

I have an Excel spreadsheet on a Sharepoint site that I would like to keep as read-only. However, my users will occasionally need to add small amounts of data, which I thought could be best stored in a small text file. I can read the text data into the Excel userform easily enough, and I can amend the text file with new data equally easy - but only if I have already checked the text file out. This doesn't work for other users of course. Is there some method of checking out a file - which isn't a workbook - out via Excel VBA, or will I have to switch to storing the updateable data in another workbook?
It is possible to use VBA to read textfiles. You can use this example for instance: https://www.excel-easy.com/vba/examples/read-data-from-text-file.html where you can read the data per line.

Non editable internal reference string for excel file

We have a web application that allows users to generate excel reports.
We would to have a way to set reference value to one of the properties of the excel file so that we can identify if the excel report belonged to our system
Most of the properties like "Title","Subject" etc are editable by a user by right clicking on the excel file > properties > details
Is there a property that is non editable by a user?
Thanks in advance
Is there a property non-editable by a user?
No.
But concerning "identify if the excel report belonged to our system", you may use some tricks. The easiest (for implementation) I can think of are:
Save the file as *.xlsb, insert a module in VBA and write something in the module. Then save the VBA with a password;
Add a very hidden worksheet and write something on it. Or simply rename the very hidden worksheet somehow, which would tell you that this is your worksheet;
Add a specific conditional formatting and do not implement it anywhere. Thus, every worksheet, that contains the conditional format would be yours;

Save logfile within Excel file using VBA

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

VBA to write data into Excel used by multiple users on a network?

Basically I have a master workbook on a network drive which is used by many to update the sheet, I want to automate this, through my research I found there are many complications with it if I automate it.
Searching on Google gave me the following suggestions and I have noted some complications with these solutions
using VBA open and write data and close it.
there are chances that Excel is already opened by others and it is in read only mode, so I can't write. Even though I tried open and write but it's taking too long getting stuck.
Share the workbook and write data
for this to happen the workbook should be opened and shared by one at least, while writing data if two people are writing data at a time there is a chance that one could overwrite data of others
using ADO write data into Excel
I don't have any idea about ADO and how it can be used to write data into Excel, saw some examples and ended up nothing to comprehend.
Set up an Access database
Connect to the database from an Excel: Go to the ribbon: Data > From Access. This almost works like a pivot table and is indeed view only.
You can also store all the data still in an Excel and again use the External Data options (From Other Sources > Wizard > Other/Advanced > (tab) Connection > Use data source name > Excel Files > OK) to connect to it from a central Excel that all users use.
For writing to your database I would recommend using VBA nonetheless, if thats beyond you then you might want to get busy with it soon as that would probably be the best way for you to enable your users to write.

excel add in to save internal data?

I am new to writing excel add-in (in C#) and trying to figure out the right way to save some internal data structures so I can restore the state the next time file is opened. I can convert data in xml or base64 strings if it makes things easier. I don't want to maintain a separate file and would like to embed this information inside excel worksheet.
Many thanks for your help.
Use a cell in an invisible sheet (you can name it, for example, "internal data sheet") for storing the information. Excel sheets have a Visible property which can be set programmatically to `xlVeryHidden' which means it can only be made visible again by a program. Here you find some more information:
http://support.microsoft.com/kb/142530/en-us

Resources