background preloader

Macro

Facebook Twitter

Avoid this potential gotcha when using add-ins to distribute Excel macros. Learn how to easily avoid this gotcha when distributing Excel macros via an add-in.

Avoid this potential gotcha when using add-ins to distribute Excel macros

Distributing an Excel add-in is a good way to distribute macros. It's an easy process, but if you choose this route, be sure to use the ThisWorkbook property carefully because it won't work as expected in the add-in. VBA's ThisWorkbook property refers to the workbook that contains the VBA code. That's why it can seem to fail when used in an add-in; it returns the name of the add-in, not the name of the workbook that's hosting the add-in. Instead of using ThisWorkbook, use ActiveWorkbook to refer to the hosting workbook instead of the add-in. Select method of Range class failed.

Julian's Excel Macro (VBA) Tips for Beginners. Undefined (last update 30/6/2010) email (without spaces) : julian.excel @ gmail.com or julian7_s @ yahoo.com Index listing A B CD E F G H IJ K L M N O P Q R S T U V W X Y Z end Excel Macros (VBA) tips for beginners.

Julian's Excel Macro (VBA) Tips for Beginners

I do not use macros that have too many lines of codes as this may confuse beginers. NOTE : Run the macros at your own risk. Auto Run [24/12/2001] (back to top) Making your macros run automatically when opening your workbook. Sub Auto_Open() Msgbox "Hello" End Sub This code would be located in the module. Private Sub Workbook_Open() Msgbox "Hello" End Sub Active Cell [5/1/2002] (back to top) An active cell is the current cell that is selected. Adding Items to a combobox [15/3/2002] (back to top) To add a combobox refer to User Form. ComboBox1.AddItem "Product A" ComboBox1.AddItem "Product B" Sub Count() myCount = Selection.Rows.Count 'Change Rows to Columns to count columns MsgBox myCount End Sub The next macro counts the number of sheets instead. Enable or disable macros in Office documents.

This article is about macro security and explains the risks of enabling macros and how the Trust Center in the 2007 Microsoft Office system can help to mitigate these risks.

Enable or disable macros in Office documents

What's new in Office 2010 The Office Blog In this article What is a macro and what is the security risk? Macros automate frequently-used tasks; many are created with VBA (Visual Basic for Applications (VBA): A macro-language version of Microsoft Visual Basic that is used to program Microsoft Windows-based applications and is included with several Microsoft programs.) and are written by software developers. Top of Page. Automate Excel » VBA: Run a Macro Line by Line. "Subscript out of Range error 9&qu. Export from excel to text file by batch. Code to Export Excel Data to Text File. How do you create text files from a spreadsheet? - excel access.

Export Part Of Spreadsheet As .csv File. Excel - Running an Excel Macro from a Command Button on the Spreadsheet. You've written the perfect macro using Excel VBA.

Excel - Running an Excel Macro from a Command Button on the Spreadsheet

Rather than having to remember a shortcut key, you would like to add a button to the worksheet to invoke the macro. There are two types of buttons that you can place on a spreadsheet. While ActiveX controls have more features, I often use a regular command button. It is easy to set up, provided you make a simple modification to your toolbar first. Right-click any toolbar and choose "Customize... " from the bottom of the pop-up menu. In the left listbox, scroll down and select Forms. The button is now added to your toolbar. You'll notice that the button has a not-very-friendly name like "Button 1". Extra Tips While editing text on the button, you will notice that the button is surrounded by diagonal lines.

Note that this Format Control dialog has only a tab for the font. This is very subtle. Using Autoshapes You can also assign a macro to any autoshape.