excel add in to save internal data? - excel

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

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.

Excel - allow saving as pdf but no saving of original document

I have a heavily formulated workbook which will be used by staff members who will paste in potentially confidential client information. The workbook then comes up with graphics and data to summarize the imputed information
In an ideal world, the people using the program will be able to Save specific sheets as a PDF and would be able to close the program without saving changes to the worksheet but Excel always demands to save the template first, THEN will allow PDFs. This is obviously a problem as if a person uses it, paste's in a client's information and saves the result as a PDF then whoever next opens the Excel workbook will have that previous client's information showing.
SO. I either need a way to tell Excel to not require compulsory saving to allow PDF conversion or another option which will result in the same thing.
I should also note that the workbook has to allow users to paste in information so I don't imagine a Read Only will help :/
I have also attempted using a Macro-Enabled Template which still has the same problem
I imagine there's a ridiculously simple solution to this.
Thanks in advance

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

Treat .mdb as .xlsx?

I recently made an Excel workbook (with the help of Stackoverflow) where I have a regular input of data (each entry is one row with different columns). I then have a macro that extracts the data from a specified row to a different sheet and saves this sheet as a .PDF.
That way, I can extract specific data from this Excel "database" to a readable pdf. I do this because I need a paper version from specific entries.
For a different project I need to implement the same principle. The only difference is that I need to work with an .mdb file where the data is stored, instead of an Excel workbook.
Is there a way I can reuse my code from Excel or is it now a completely different story?
Thank you for the advice.
You can link your excel workbook to your Access tables. On the "DATA" ribbon there is a section for "External Data".
Once you've got the Access data displayed on one of your worksheets, you should be able to adapt your existing code accordingly.
From Microsoft:
Connect an Access database to your workbook

Is it possible to save table data into another macro?

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

Resources