Category Archives: Excel

Use VBA macros to add hyperlinks to external files

My book Essential Algorithms: A Practical Approach to Computer Algorithms has associated instructor materials that include lesson plans and PowerPoint presentations that are accessible via hyperlinks. The materials include a summary Excel workbook that contains hyperlinks that let you open … Continue reading

Posted in Excel, Office, PowerPoint, Word | Tagged , , , , , , , , , , , , , | Leave a comment

Use VBA to randomize cells in Excel

This is quick excursion into Excel VBA programming. This example uses a VBA macro to let you randomize the selected cells in an Excel workbook. If you select a contiguous block of cells and click the Randomize button, the following … Continue reading

Posted in Excel, Office, VBA | Tagged , , , , , , , , , , , , , | Leave a comment

Save Excel data in a PDF file in C#

This example extends the example Write Excel data in C#. See that example for information on how to open an Excel workbook, write data into it, and save it. Note that before you can use the Excel interop library, you … Continue reading

Posted in Excel, Office | Tagged , , , , , , , , , , | 1 Comment

Load a CSV file in Excel in C#

Loading a CSV file (comma-separated value file) into Excel isn’t too hard once you know the tricks. Using the same tricks you can load a file that uses any delimiter, not just a comma. First at design time, add a … Continue reading

Posted in Excel, files, Office | Tagged , , , , , , , , , , , , | 5 Comments

Make an Excel chart in C#

This example uses the following code to create an Excel chart in a new workbook. private void btnCreateChart_Click( object sender, EventArgs e) { // Get the Excel application object. Excel.Application excel_app = new Excel.ApplicationClass(); // Make Excel visible (optional). excel_app.Visible … Continue reading

Posted in Excel, interoperability, Office | Tagged , , , , , , , , , , | Leave a comment

Add and remove pictures in an Excel worksheet

This is another brief foray into VBA programming. When you click the Insert Image button, the following VBA code executes. ‘ Insert a picture at the selection. Sub Button1_Click() Dim filters As String Dim filename As Variant ‘ Define the … Continue reading

Posted in Excel, Office, VBA | Tagged , , , , , , , , , | Leave a comment

Read Excel data in C#

To read Excel data, you can open the Excel application and use it as a server to manipulate Excel workbooks. First open the Add References dialog. On the COM tab, select “Microsoft Excel 14.0 Object Library” (or whatever version you … Continue reading

Posted in Excel, Office | Tagged , , , , , , , , , | 4 Comments

Write Excel data in C#

This example shows how to write Excel data into a workbook. You can do that by opening the Excel application and use it as a server to manipulate Excel workbooks. First open the Add References dialog. On the COM tab, … Continue reading

Posted in Excel, Office | Tagged , , , , , , , , , | 3 Comments

Use VBA code to pick random cells from the currently selected cells in an Excel workbook

This example shows how you can use VBA code to pick random cells in an Excel workbook. Sooner or later, many programmers need to write code to control another application such as the Microsoft Office applications, either for their own … Continue reading

Posted in Excel, VBA | Tagged , , , , , , , , , , | Leave a comment

Convert between Excel column numbers and names in C#

Excel uses both numbers and names to identify columns. A = 1, B = 2, …, Z = 26, AZ = 27, …, XFD = 16,384. This example converts between these Excel-style column numbers and names. It’s a little trickier … Continue reading

Posted in algorithms, Excel, Office | Tagged , , , , , , , , , | 2 Comments