<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Peltier Tech Blog &#187; VBA</title>
	<atom:link href="http://peltiertech.com/WordPress/category/vba/feed/" rel="self" type="application/rss+xml" />
	<link>http://peltiertech.com/WordPress</link>
	<description>Peltier Tech Excel Charts and Programming Blog</description>
	<lastBuildDate>Wed, 17 Mar 2010 07:00:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Build an Excel Add-In 6 – Interface for 2003</title>
		<link>http://peltiertech.com/WordPress/build-an-excel-add-in-6-%e2%80%93-interface-for-2003/</link>
		<comments>http://peltiertech.com/WordPress/build-an-excel-add-in-6-%e2%80%93-interface-for-2003/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 07:00:01 +0000</pubDate>
		<dc:creator>Jon Peltier</dc:creator>
				<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=3175</guid>
		<description><![CDATA[This is the sixth of nine installments in the Build an Excel Add-In series. In previous installments, we wrote some code to perform a useful task, enhanced its functionality to make it more broadly applicable, modularized the code and included an auxiliary modular procedure, built a dialog to ask the user for preferences, and brought [...]]]></description>
			<content:encoded><![CDATA[<p>This is the sixth of nine installments in the <strong>Build an Excel Add-In</strong> series. In previous installments, we wrote some code to perform a useful task, enhanced its functionality to make it more broadly applicable, modularized the code and included an auxiliary modular procedure, built a dialog to ask the user for preferences, and brought all the code together. What remains is to construct the user interface elements for Classic Excel (2003 and earlier) and for new Excel (2007 and later), tie up a few loose ends, and create a setup file for easy deployment. A linked outline can be found at the end of this article.</p>
<h2>Microsoft Office User Interfaces</h2>
<p>Microsoft introduced a flexible and powerful user interface system in Office 97, and this interface has remained in use through Office 2003 (and a subset remains in use in later versions). The user interface consists of various command bars, which include menu bars and toolbars. Command bars can contain menus as well as buttons. Menus can contain submenus and buttons. Submenus can contain, well, you get the idea. This system of menus, toolbars, and buttons is easily customized through the user interface and via VBA.</p>
<p>Here is what our add-in&#8217;s menu customizations look like. This article shows how to create these customizations.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-03/PTPlot_2003Menu.png" alt="Excel macros dialog" /></p>
<p><span id="more-3175"></span>The Microsoft Office development team at Microsoft noticed some things about the command-bar-style interface, and about how users interacted with it. The interface was becoming complicated, with three or more levels of menus and submenus existing in some places. Each application ended up with its Tools menu, a kitchen junk drawer of commands that didn&#8217;t logically fit into the other menus. Users didn&#8217;t know what all the features were, or couldn&#8217;t find them, if they were buried more than a level deep, so they kept suggesting new features which already existed. Many users also didn&#8217;t know how to clean up their interfaces, so there were too many rows of docked toolbars and too many floating toolbars obstructing the workspace.</p>
<p>In response to the complicated nature of the command-bar-based interface and to the inability of some users to learn to use it as intended, the Microsoft Office team gutted the interface, replacing most toolbar implementations in favor of a new Ribbon in Office 2007. The ribbon is controlled using XML instead of VBA. Instead of toolbars which are visible all or most of the time, the ribbon has a set of different tabs. These tabs contain fewer buttons, and the buttons used more tend to be larger. The tabs become visible when the Office program thinks you might want to use them, and invisible when you actually do want to use them. No parts of the new interface can be undocked, so users who didn&#8217;t know how to click the close box of a floating toolbar now have clean interfaces, while users who like dispatching toolbars and palettes to areas on the screen where they are needed have to resort to extra mouse travel distances and excess mouse clicks. The ribbon-based interface is easy to customize using the RibbonX XML dialect and related VBA callbacks, but it is practically inaccessable through the user interface. Unless, of course, you count the QAT (Quick Access Toolbar), which is like a Classic toolbar on strong sedatives. Fortunately the ability of a user to customize their own interface was resuscitated for use in Office 2010.</p>
<p>This article will show how to construct a simple set of Classic Excel menu and toolbar  customizations using VBA. The next article in the sequence will show simple XML code and VBA callbacks for use in New Excel.</p>
<h2>Classic Excel User Interface Code</h2>
<p>The object model for the Office command bar system is straightforward. The CommandBars collection contains menu bars, standard toolbars, and popup menus (context or right-click menus). There is a lot of documentation of this system on the internet. This article shows a set of simple, hard-coded routines, all that is necessary for this simple add-in. There are a number of examples of more elaborate and flexible routines that use tables in Excel workbooks to define all of the interface elements to be created. John Walkenbach describes <a href="http://spreadsheetpage.com/index.php/tip/creating_custom_menus/" rel="nofollow" title="Spreadsheet Page Excel Tips: Creating Custom Menus" >Creating Custom Menus</a> using his <strong>MenuMakr</strong> system. I started with his system, but like any good engineer, I tweaked it beyond all recognition to create the system I use in my own add-ins and in projects for my clients.</p>
<p>Here is the simple code in its entirety, copied out of its code module. Explanations for selected sections of the code follow the complete listing.</p>
<pre class="vbasmall"><code><span style="color: #339966;">''========================================================================
'' Peltier Technical Services, Inc., Copyright © 2010. All rights reserved.
''========================================================================
</span>Option Explicit

Const sMenuName As String = "&amp;PTS Charts"
Const sToolbars As String = "Worksheet Menu Bar|Chart Menu Bar|PTS Charts"
Const sButton As String = "PT_Plotter"
Const sOnAction As String = "PT_Plotter_Dialog"

Sub Create_PTPlotter_Menu()
  Dim ctlpop As CommandBarPopup
  Dim ctlbtn As CommandBarButton
  Dim iMenu As Long
  Dim vMenu As Variant

  Delete_PTPlotter_Menu

  vMenu = Split(sToolbars, "|")

  For iMenu = LBound(vMenu) To UBound(vMenu)
    On Error Resume Next
    If Application.CommandBars(vMenu(iMenu)) Is Nothing Then
      With Application.CommandBars.Add(vMenu(iMenu), msoBarFloating)
        .Left = Application.Left + Application.Width / 4
        .Top = Application.Top + 144
        .Visible = True
      End With
    End If
    On Error GoTo 0

    With Application.CommandBars(vMenu(iMenu))
      On Error Resume Next
      If .Type = msoBarTypeMenuBar Then
        Set ctlpop = .Controls(sMenuName)
        On Error GoTo 0
        If ctlpop Is Nothing Then
          Set ctlpop = .Controls.Add(10, 1, , , True)
          With ctlpop
            .Caption = sMenuName
            .Visible = True
          End With
        End If
        Set ctlbtn = ctlpop.Controls.Add(1, 1, , , True)
      Else
        Set ctlbtn = .Controls.Add(1, 1, , , True)
        .Visible = True
      End If

      With ctlbtn
        .Caption = sButton
        .OnAction = "'" &amp; ThisWorkbook.Name &amp; "'!" &amp; sOnAction
        .TooltipText = "Create chart from arbitrary data range"
        .FaceId = 422
        .Visible = True
      End With
      Set ctlpop = Nothing
    End With
  Next
End Sub

Sub Delete_PTPlotter_Menu()
  Dim ctlpop As CommandBarPopup
  Dim ctlbtn As CommandBarControl
  Dim iMenu As Long
  Dim vMenu As Variant

  On Error Resume Next
  vMenu = Split(sToolbars, "|")

  For iMenu = LBound(vMenu) To UBound(vMenu)
    With Application.CommandBars(vMenu(iMenu))
      If .Type = msoBarTypeMenuBar Then
        Set ctlpop = .Controls(sMenuName)
        Do
          Set ctlbtn = ctlpop.Controls(sButton)
          If ctlbtn Is Nothing Then Exit Do
          ctlbtn.Delete
          Set ctlbtn = Nothing
        Loop

        If ctlpop.Controls.Count = 0 Then
          ctlpop.Delete
        End If
      Else
        Do
          Set ctlbtn = .Controls(sButton)
          If ctlbtn Is Nothing Then Exit Do
          ctlbtn.Delete
          Set ctlbtn = Nothing
        Loop

        If .Controls.Count = 0 Then
          .Delete
        End If

      End If
    End With
  Next
</code></pre>
<h1><code>End Sub</code></h1>
<h2>Explanations</h2>
<p>The module starts by defining a few constants. The menu name <tt class="tt">sMenuName</tt>, &#8220;&amp;PTS Charts&#8221; has an ampersand that tells Excel to use the next character (P) as an accelerator key, that is, to activate the menu when Alt plus the next character is pressed (Alt+P). This character will appear underlined in the menu name: <span style="text-decoration: underline;">&#8220;P</span>TS Charts&#8221;.</p>
<p><tt class="tt">sToolBars</tt> is a pipe-delimited string of command bars which will be customized. The remaining constants list the button caption and the name of the procedure to be run when the button is clicked.</p>
<p><tt class="tt">Create_PTPlotter_Menu</tt> is the routine that adds our buttons to the Classic Excel interface. The first command in this routine is <tt class="tt">Delete_PTPlotter_Menu</tt>, which removes any existing buttons from this add-in which have somehow been orphaned due to a disorderly shutdown.</p>
<p>The pipe-delimited string is converted into an array of command bar names. The program loops through this array, looking for command bars with each name. If such a command bar is not found, then a new standard command bar is created using that name, other wise the program continues with the found command bar.</p>
<p>If the command bar is a menu bar, the program looks for a menu with the indicated name. If such a menu is not found on the command bar, a new menu is created, otherwise the existing menu is used. Then the button is placed on the menu. If the command bar is a regular toolbar, the button is placed directly on the toolbar.</p>
<p>The caption of the button is assigned, as is the name of the procedure to run when the button is clicked. The procedure name is prepended with the workbook name in single quotes, so Excel will not confuse our procedure with a procedure with the same name in another workbook.</p>
<p>The button is assigned its tooltip text, which appears when the cursor passes over the button.</p>
<p>Built-in button image number 422 is used for the button&#8217;s icon. <a href="http://peltiertech.com/Excel/Zips/ShowFace.zip" rel="nofollow" title="Display FaceIDs" >Display FaceIDs</a> is a simple utility that helps you browse Excel&#8217;s button images. Not described here is the means to assign a custom button image.</p>
<p>Finally the button is made visible, so users can find it.</p>
<p><tt class="tt">Delete_PTPlotter_Menu</tt> goes through the command bars listed in the pipe-delimited string, looking for buttons with the name used by our add-in. This is done inside Do loops, in case multiple crashes left behind multiple identical buttons. If the last button of a menu or toolbar is deleted, the empty menu or toolbar is also deleted.</p>
<h2>Our Menu and Toolbar</h2>
<p>The menu and toolbar customizations produced by the code above are displayed below.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-03/PTPlot_2003Menu.png" alt="Excel macros dialog" /></p>
<p>The menu is on the Worksheet Menu Bar; the menu on the Chart menu Bar is the same. The PTS Charts menu and the PTS Charts toolbar already existed, with a variety of my utilities displayed, and the PT_Plotter button is added at the end of the list.</p>
<h2>Contents: How to Build an Excel Add-In</h2>
<ul style="margin-left: 24pt;">
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-1-basic-routine/"title="Build an Excel Add-In 1 – Basic Routine" >Build an Excel Add-In 1 – Basic Routine</a></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-2-enhanced-functionality/"title="Build an Excel Add-In 2 – Enhanced Functionality" >Build an Excel Add-In 2 – Enhanced Functionality</a></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-3-auxiliary-modular-functions/"title="Build an Excel Add-In 3 - Auxiliary Modular Functions" >Build an Excel Add-In 3 – Auxiliary Modular Functions</a></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-4-create-the-dialog/"title="Build an Excel Add-In 4 – Create the Dialog" >Build an Excel Add-In 4 – Create the Dialog</a></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-5-tie-it-all-together/"title="Build an Excel Add-In 5 – Tie the Code Together" >Build an Excel Add-In 5 – Tie the Code Together</a></li>
<li><strong>Build an Excel Add-In 6 – Interface for 2003</strong></li>
<li>Build an Excel Add-In 7 – Interface for 2007</li>
<li>Build an Excel Add-In 8 – Last Steps</li>
<li>Build an Excel Add-In 9 – Deployment</li>
</ul>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 2363px; width: 1px; height: 1px; overflow: hidden;">
<pre class="vbasmall"><code>Create_LblLastPt_Menu</code></pre>
</div>



Bookmark and share this entry:


	<a rel="nofollow"  href="http://twitter.com/home?status=Build%20an%20Excel%20Add-In%206%20%E2%80%93%20Interface%20for%202003%20-%20http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-6-%25e2%2580%2593-interface-for-2003%2F" title="Twitter"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-6-%25e2%2580%2593-interface-for-2003%2F&amp;title=Build%20an%20Excel%20Add-In%206%20%E2%80%93%20Interface%20for%202003&amp;bodytext=This%20is%20the%20sixth%20of%20nine%20installments%20in%20the%20Build%20an%20Excel%20Add-In%20series.%20In%20previous%20installments%2C%20we%20wrote%20some%20code%20to%20perform%20a%20useful%20task%2C%20enhanced%20its%20functionality%20to%20make%20it%20more%20broadly%20applicable%2C%20modularized%20the%20code%20and%20included%20an%20aux" title="Digg"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-6-%25e2%2580%2593-interface-for-2003%2F&amp;t=Build%20an%20Excel%20Add-In%206%20%E2%80%93%20Interface%20for%202003" title="Facebook"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-6-%25e2%2580%2593-interface-for-2003%2F&amp;title=Build%20an%20Excel%20Add-In%206%20%E2%80%93%20Interface%20for%202003&amp;source=Peltier+Tech+Blog+Peltier+Tech+Excel+Charts+and+Programming+Blog&amp;summary=This%20is%20the%20sixth%20of%20nine%20installments%20in%20the%20Build%20an%20Excel%20Add-In%20series.%20In%20previous%20installments%2C%20we%20wrote%20some%20code%20to%20perform%20a%20useful%20task%2C%20enhanced%20its%20functionality%20to%20make%20it%20more%20broadly%20applicable%2C%20modularized%20the%20code%20and%20included%20an%20aux" title="LinkedIn"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-6-%25e2%2580%2593-interface-for-2003%2F&amp;title=Build%20an%20Excel%20Add-In%206%20%E2%80%93%20Interface%20for%202003&amp;notes=This%20is%20the%20sixth%20of%20nine%20installments%20in%20the%20Build%20an%20Excel%20Add-In%20series.%20In%20previous%20installments%2C%20we%20wrote%20some%20code%20to%20perform%20a%20useful%20task%2C%20enhanced%20its%20functionality%20to%20make%20it%20more%20broadly%20applicable%2C%20modularized%20the%20code%20and%20included%20an%20aux" title="del.icio.us"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-6-%25e2%2580%2593-interface-for-2003%2F" title="Technorati"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-6-%25e2%2580%2593-interface-for-2003%2F&amp;title=Build%20an%20Excel%20Add-In%206%20%E2%80%93%20Interface%20for%202003" title="StumbleUpon"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-6-%25e2%2580%2593-interface-for-2003%2F&amp;title=Build%20an%20Excel%20Add-In%206%20%E2%80%93%20Interface%20for%202003&amp;annotation=This%20is%20the%20sixth%20of%20nine%20installments%20in%20the%20Build%20an%20Excel%20Add-In%20series.%20In%20previous%20installments%2C%20we%20wrote%20some%20code%20to%20perform%20a%20useful%20task%2C%20enhanced%20its%20functionality%20to%20make%20it%20more%20broadly%20applicable%2C%20modularized%20the%20code%20and%20included%20an%20aux" title="Google Bookmarks"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-6-%25e2%2580%2593-interface-for-2003%2F&amp;title=Build%20an%20Excel%20Add-In%206%20%E2%80%93%20Interface%20for%202003" title="Reddit"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-6-%25e2%2580%2593-interface-for-2003%2F&amp;t=Build%20an%20Excel%20Add-In%206%20%E2%80%93%20Interface%20for%202003" title="MySpace"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Build%20an%20Excel%20Add-In%206%20%E2%80%93%20Interface%20for%202003&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-6-%25e2%2580%2593-interface-for-2003%2F" title="Slashdot"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-6-%25e2%2580%2593-interface-for-2003%2F&amp;submitHeadline=Build%20an%20Excel%20Add-In%206%20%E2%80%93%20Interface%20for%202003&amp;submitSummary=This%20is%20the%20sixth%20of%20nine%20installments%20in%20the%20Build%20an%20Excel%20Add-In%20series.%20In%20previous%20installments%2C%20we%20wrote%20some%20code%20to%20perform%20a%20useful%20task%2C%20enhanced%20its%20functionality%20to%20make%20it%20more%20broadly%20applicable%2C%20modularized%20the%20code%20and%20included%20an%20aux&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-6-%25e2%2580%2593-interface-for-2003%2F&amp;t=Build%20an%20Excel%20Add-In%206%20%E2%80%93%20Interface%20for%202003&amp;s=This%20is%20the%20sixth%20of%20nine%20installments%20in%20the%20Build%20an%20Excel%20Add-In%20series.%20In%20previous%20installments%2C%20we%20wrote%20some%20code%20to%20perform%20a%20useful%20task%2C%20enhanced%20its%20functionality%20to%20make%20it%20more%20broadly%20applicable%2C%20modularized%20the%20code%20and%20included%20an%20aux" title="Tumblr"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://peltiertech.com/WordPress/build-an-excel-add-in-6-%e2%80%93-interface-for-2003/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Recorded Macro Error with Bubble and Stock Charts</title>
		<link>http://peltiertech.com/WordPress/recorded-macro-error-with-bubble-and-stock-charts/</link>
		<comments>http://peltiertech.com/WordPress/recorded-macro-error-with-bubble-and-stock-charts/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 06:00:34 +0000</pubDate>
		<dc:creator>Jon Peltier</dc:creator>
				<category><![CDATA[VBA]]></category>
		<category><![CDATA[VBA Errors]]></category>

		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=3018</guid>
		<description><![CDATA[You have a chart that you make every week or every month, and you&#8217;re tired of making it from scratch every time. So you record a macro to automate the process.
When you run the macro to make your chart the next time, you get no chart. Instead you get an ugly error message.

That&#8217;s frustrating. All [...]]]></description>
			<content:encoded><![CDATA[<p>You have a chart that you make every week or every month, and you&#8217;re tired of making it from scratch every time. So you record a macro to automate the process.</p>
<p>When you run the macro to make your chart the next time, you get no chart. Instead you get an ugly error message.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/VBA_Error.png" alt="Chart Type VBA Error" /></p>
<p><span id="more-3018"></span>That&#8217;s frustrating. All you did was record and rerun a macro. You didn&#8217;t even change the code, so at least this once, you <em>couldn&#8217;t</em> have messed it up. And still it crashed.</p>
<p>Let&#8217;s examine the macro recorder code.</p>
<pre class="vbasmall"><code>Sub RecordedMacro_MakeBubbleChart()
<span style="color: #339966;">'
' RecordedMacro_MakeBubbleChart Macro
' Macro recorded 1/26/2010 by Jon Peltier
'

'
</span>    Charts.Add
    <span style="color: #0000ff;">ActiveChart.ChartType = xlBubble</span>
    <span style="color: #ff6600;">ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:C7"), _
        PlotBy:=xlColumns</span>
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
End Sub
</code></pre>
<p>The macro recorder follow the order of the Excel 2003 chart wizard, putting the chart type before the chart source data. The steps given by the recorder work fine for most chart types, but a few chart types cannot be correctly assigned until the chart has been populated with sufficient data. In particular, code which creates <strong>stock charts</strong> and <strong>bubble charts</strong> will fail if you set the chart type before the chart is populated with data.</p>
<p>To make the code run properly without crashing, all you need to do is switch the <tt class="tt" style="color: #ff6600;">SetSourceData</tt> and <tt class="tt" style="color: #0000ff;">ChartType</tt> commands. The following code works fine.</p>
<pre class="vbasmall"><code>Sub RecordedMacro_MakeBubbleChart()
<span style="color: #339966;">'
' RecordedMacro_MakeBubbleChart Macro
' Macro recorded 1/26/2010 by Jon Peltier
'

'
</span>    Charts.Add
    <span style="color: #ff6600;">ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:C7"), _
        PlotBy:=xlColumns</span>
    <span style="color: #0000ff;">ActiveChart.ChartType = xlBubble</span>
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
End Sub
</code></pre>
<p>This code isn&#8217;t particularly efficient, but at least it works. You can improve it following the suggestions in <a href="http://peltiertech.com/WordPress/how-to-fix-a-recorded-macro/"title="How To: Fix a Recorded Macro" >How To Fix a Recorded Macro</a>.</p>
<p>This error has existed in Excel from the first modern version (Excel 97) through Excel 2003. Microsoft must have received inquiries about the problem, and they addressed it with a KB article, <a href="http://support.microsoft.com/kb/139662" rel="nofollow" title="How to Use a Visual Basic Macro to Create a Bubble Chart" >How to Use a Visual Basic Macro to Create a Bubble Chart</a>., which propagated through versions 5/95, 97, 2000, 2002, and 2003. The author of the article didn&#8217;t think to rearrange the two VBA commands, so he wrote a long procedure that made an XY chart, and for markers, the chart used custom AutoShape circles sized according to the bubble values. It&#8217;s a nice procedure and a nice technique to know, but also a long voyage to go such a short distance.</p>
<p>When Microsoft rebuilt the charting infrastructure for Excel 2007, they changed some of the code produced by the macro recorder. Here is the Excel 2007 bubble chart macro:</p>
<pre class="vbasmall"><code>Sub RecordedMacro_MakeBubbleChart()
<span style="color: #339966;">'
' RecordedMacro_MakeBubbleChart Macro
' Macro recorded 1/26/2010 by Jon Peltier
'

'</span>
  ActiveSheet.Shapes.AddChart.Select
  ActiveChart.SetSourceData Source:=Range("'Sheet1'!$A$1:$C$5")
  ActiveChart.ChartType = xlBubble
End Sub
</code></pre>
<p>Excel 2007&#8217;s macro recorder has been criticized because it didn&#8217;t capture any actions that affected the new shapes which comprise the chart. But in the simple macro above, we see that some improvements were made to Excel 2007&#8217;s macro recorder:</p>
<ul style="margin-left: 24px;">
<li>In earlier versions of Excel, a separate chart sheet is made, then later inserted in the worksheet. In 2007, a chart is directly added to the worksheet&#8217;s Shapes collection. That&#8217;s more efficient.</li>
<li>More important, the chart type is not set until after the chart is populated with data. The error in recorded macros no longer occurs.</li>
</ul>
<p>Peltier Technical Services, Inc., Copyright © 2010.<br /> <br /><span style="font: 80% Verdana,Tahoma,Arial,sans-serif;">Licensed under a <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/" rel="nofollow" rel="license" >Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.<br /> <br />
<a href="http://www.exceluser.com/cmd.asp?Clk=1374689" rel="nofollow" ><IMG SRC="http://www.exceluser.com/images/info/pub/info_dash_c02.gif" ALT="Learn how to create Excel dashboards." WIDTH="468" HEIGHT="60" border=0></a><br />
<br /><img src="http://www.exceluser.com/cmd.asp?Imp=1374689" width="0" height="0" border="0"></p>



Bookmark and share this entry:


	<a rel="nofollow"  href="http://twitter.com/home?status=Recorded%20Macro%20Error%20with%20Bubble%20and%20Stock%20Charts%20-%20http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frecorded-macro-error-with-bubble-and-stock-charts%2F" title="Twitter"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frecorded-macro-error-with-bubble-and-stock-charts%2F&amp;title=Recorded%20Macro%20Error%20with%20Bubble%20and%20Stock%20Charts&amp;bodytext=You%20have%20a%20chart%20that%20you%20make%20every%20week%20or%20every%20month%2C%20and%20you%27re%20tired%20of%20making%20it%20from%20scratch%20every%20time.%20So%20you%20record%20a%20macro%20to%20automate%20the%20process.%0D%0A%0D%0AWhen%20you%20run%20the%20macro%20to%20make%20your%20chart%20the%20next%20time%2C%20you%20get%20no%20chart.%20Instead%20you%20" title="Digg"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frecorded-macro-error-with-bubble-and-stock-charts%2F&amp;t=Recorded%20Macro%20Error%20with%20Bubble%20and%20Stock%20Charts" title="Facebook"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frecorded-macro-error-with-bubble-and-stock-charts%2F&amp;title=Recorded%20Macro%20Error%20with%20Bubble%20and%20Stock%20Charts&amp;source=Peltier+Tech+Blog+Peltier+Tech+Excel+Charts+and+Programming+Blog&amp;summary=You%20have%20a%20chart%20that%20you%20make%20every%20week%20or%20every%20month%2C%20and%20you%27re%20tired%20of%20making%20it%20from%20scratch%20every%20time.%20So%20you%20record%20a%20macro%20to%20automate%20the%20process.%0D%0A%0D%0AWhen%20you%20run%20the%20macro%20to%20make%20your%20chart%20the%20next%20time%2C%20you%20get%20no%20chart.%20Instead%20you%20" title="LinkedIn"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frecorded-macro-error-with-bubble-and-stock-charts%2F&amp;title=Recorded%20Macro%20Error%20with%20Bubble%20and%20Stock%20Charts&amp;notes=You%20have%20a%20chart%20that%20you%20make%20every%20week%20or%20every%20month%2C%20and%20you%27re%20tired%20of%20making%20it%20from%20scratch%20every%20time.%20So%20you%20record%20a%20macro%20to%20automate%20the%20process.%0D%0A%0D%0AWhen%20you%20run%20the%20macro%20to%20make%20your%20chart%20the%20next%20time%2C%20you%20get%20no%20chart.%20Instead%20you%20" title="del.icio.us"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frecorded-macro-error-with-bubble-and-stock-charts%2F" title="Technorati"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frecorded-macro-error-with-bubble-and-stock-charts%2F&amp;title=Recorded%20Macro%20Error%20with%20Bubble%20and%20Stock%20Charts" title="StumbleUpon"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frecorded-macro-error-with-bubble-and-stock-charts%2F&amp;title=Recorded%20Macro%20Error%20with%20Bubble%20and%20Stock%20Charts&amp;annotation=You%20have%20a%20chart%20that%20you%20make%20every%20week%20or%20every%20month%2C%20and%20you%27re%20tired%20of%20making%20it%20from%20scratch%20every%20time.%20So%20you%20record%20a%20macro%20to%20automate%20the%20process.%0D%0A%0D%0AWhen%20you%20run%20the%20macro%20to%20make%20your%20chart%20the%20next%20time%2C%20you%20get%20no%20chart.%20Instead%20you%20" title="Google Bookmarks"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frecorded-macro-error-with-bubble-and-stock-charts%2F&amp;title=Recorded%20Macro%20Error%20with%20Bubble%20and%20Stock%20Charts" title="Reddit"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frecorded-macro-error-with-bubble-and-stock-charts%2F&amp;t=Recorded%20Macro%20Error%20with%20Bubble%20and%20Stock%20Charts" title="MySpace"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Recorded%20Macro%20Error%20with%20Bubble%20and%20Stock%20Charts&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frecorded-macro-error-with-bubble-and-stock-charts%2F" title="Slashdot"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frecorded-macro-error-with-bubble-and-stock-charts%2F&amp;submitHeadline=Recorded%20Macro%20Error%20with%20Bubble%20and%20Stock%20Charts&amp;submitSummary=You%20have%20a%20chart%20that%20you%20make%20every%20week%20or%20every%20month%2C%20and%20you%27re%20tired%20of%20making%20it%20from%20scratch%20every%20time.%20So%20you%20record%20a%20macro%20to%20automate%20the%20process.%0D%0A%0D%0AWhen%20you%20run%20the%20macro%20to%20make%20your%20chart%20the%20next%20time%2C%20you%20get%20no%20chart.%20Instead%20you%20&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frecorded-macro-error-with-bubble-and-stock-charts%2F&amp;t=Recorded%20Macro%20Error%20with%20Bubble%20and%20Stock%20Charts&amp;s=You%20have%20a%20chart%20that%20you%20make%20every%20week%20or%20every%20month%2C%20and%20you%27re%20tired%20of%20making%20it%20from%20scratch%20every%20time.%20So%20you%20record%20a%20macro%20to%20automate%20the%20process.%0D%0A%0D%0AWhen%20you%20run%20the%20macro%20to%20make%20your%20chart%20the%20next%20time%2C%20you%20get%20no%20chart.%20Instead%20you%20" title="Tumblr"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://peltiertech.com/WordPress/recorded-macro-error-with-bubble-and-stock-charts/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Build an Excel Add-In 5 &#8211; Tie the Code Together</title>
		<link>http://peltiertech.com/WordPress/build-an-excel-add-in-5-tie-it-all-together/</link>
		<comments>http://peltiertech.com/WordPress/build-an-excel-add-in-5-tie-it-all-together/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 06:00:04 +0000</pubDate>
		<dc:creator>Jon Peltier</dc:creator>
				<category><![CDATA[VBA]]></category>
		<category><![CDATA[Add-ins]]></category>

		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=2982</guid>
		<description><![CDATA[This is the fifth in a series of posts that shows the steps involved in building an Excel add-in. In Build an Excel Add-In 1 – Basic Routine I showed a VBA procedure that creates a regular chart from an arbitrary rectangular range, including from a pivot table. In Build an Excel Add-In 2 – [...]]]></description>
			<content:encoded><![CDATA[<p>This is the fifth in a series of posts that shows the steps involved in building an Excel add-in. In <a href="../build-an-excel-add-in-1-basic-routine/" rel="nofollow" title="Build an Excel Add-In 1 – Basic Routine" >Build an Excel Add-In 1 – Basic Routine</a> I showed a VBA procedure that creates a regular chart from an arbitrary rectangular range, including from a pivot table. In <a href="../build-an-excel-add-in-2-enhanced-functionality/" rel="nofollow" title="Build an Excel Add-In 2 – Enhanced Functionality | PTS Blog" >Build an Excel Add-In 2 – Enhanced Functionality</a> I turned modularized this routine, so it could be called from any code that passed the appropriate settings into the function as arguments. In <a href="../build-an-excel-add-in-3-auxiliary-modular-functions/" rel="nofollow" title="Build an Excel Add-In 3 - Auxiliary Modular Functions" >Build an Excel Add-In 3 – Auxiliary Modular Functions</a> I included an additional modular function which cleans up the chart created in the previous article&#8217;s code. Because this function is widely useful, it will be made more general in a future article, after this series is finished. In <a href="http://peltiertech.com/WordPress/build-an-excel-add-in-4-create-the-dialog/"title="Build an Excel Add-In 4 – Create the Dialog" >Build an Excel Add-In 4 – Create the Dialog</a> I showed a simple dialog that asked the user to identify the data to plot and select a few simple options.</p>
<p>In this installment of the <strong>Build an Excel Add-In</strong> series, I will show a VBA procedure that ties together all of the pieces that we&#8217;ve built so far. This master procedure is really a short list of the other procedures that do the individual tasks.</p>
<p><span id="more-2982"></span>Here is the master procedure in its entirety. Below this, the individual pieces will be explained.</p>
<pre class="vbasmall"><code>Sub PT_Plotter_Dialog()

  <span style="color: #008000;">' GET USER SPECIFICATIONS
  ' ' Using custom dialog
  ' ' Get data range and orientation
  ' ' Get header rows and columns
  ' ' Get chart type
  ' ' Get optional chart position and size</span>

  Dim frmPlotSetup As FPlotSetup
  Dim rChartData As Range
  Dim Orientation As XlRowCol
  Dim iHeaderRows As Long
  Dim iHeaderCols As Long
  Dim ChtType As XlChartType
  Dim rPosition As Range
  Dim bCancel As Boolean
  Dim PT_Plot As Chart

  Set frmPlotSetup = New FPlotSetup
  With frmPlotSetup
    .Show

    bCancel = .Cancel
    If Not bCancel Then
      Set rChartData = .ChartDataRange
      Orientation = .DataOrientation
      iHeaderRows = .HeaderRows
      iHeaderCols = .HeaderColumns
      ChtType = .ChartType
      Set rPosition = .ChartPosition
    End If
  End With
  Set frmPlotSetup = Nothing

  If Not bCancel Then
    Application.ScreenUpdating = False

    <span style="color: #008000;">' make the chart</span>
    Set PT_Plot = PT_Plotter_Chart(rChartData, Orientation, _
        iHeaderRows, iHeaderCols, ChtType, rPosition)

    <span style="color: #008000;">' clean up the chart</span>
    Set PT_Plot = CleanUpChart(PT_Plot)

    Application.ScreenUpdating = True
  End If

ExitSub:

End Sub</code></pre>
<p>After the declarations, the program calls the dialog to get the user&#8217;s settings.</p>
<pre class="vbasmall"><code>  <span style="color: #008000;">' declare a new instance of the dialog class
  ' this may be overkill, but it's done this way in PED</span>
  Set frmPlotSetup = New FPlotSetup
  With frmPlotSetup
    <span style="color: #008000;">' display the dialog</span>
    .Show

    <span style="color: #008000;">' execution returns here when user dismisses dialog
    ' first see whether user canceled</span>
    bCancel = .Cancel
    If Not bCancel Then
      <span style="color: #008000;">' if user did not cancel, we need the information</span>
      Set rChartData = .ChartDataRange
      Orientation = .DataOrientation
      iHeaderRows = .HeaderRows
      iHeaderCols = .HeaderColumns
      ChtType = .ChartType
      Set rPosition = .ChartPosition
    End If
  End With
  <span style="color: #008000;">' we're done with the form, so destroy it</span>
  Set frmPlotSetup = Nothing</code></pre>
<p>Now that we&#8217;ve retrieved the user settings, it&#8217;s time to make the chart, then clean it up.</p>
<pre class="vbasmall"><code>  <span style="color: #008000;">' skip the rest if the user has canceled</span>
  If Not bCancel Then
    <span style="color: #008000;">' prevent seizures and speed execution</span>
    Application.ScreenUpdating = False

    <span style="color: #008000;">' call the PT_Plotter_Chart function, pass in user info,
    ' function returns the chart
</span>    Set PT_Plot = PT_Plotter_Chart(rChartData, Orientation, _
        iHeaderRows, iHeaderCols, ChtType, rPosition)

    <span style="color: #008000;">' call the CleanUpChart function to, uh, clean up the chart
    ' pass in the chart, and it is returned in cleaned state</span>
    Set PT_Plot = CleanUpChart(PT_Plot)

    <span style="color: #008000;">' turn display updating back on</span>
    Application.ScreenUpdating = True
  End If
</code></pre>
<p>In the next two articles, we&#8217;ll create the user interface for Classic Excel (menu and command bar elements in Excel 2000 through 2003) and for New Excel (ribbon elements in Excel 2007 and 2010). There is some clean up to do, including modifications to make the add-in work for both Classic and new Excel, and a trick to improve the chances of compatibility with as many users as possible. Finally I will cover deployment using <a href="http://www.jrsoftware.org/isinfo.php" rel="nofollow" title="Inno Setup. A powerful script based freeware installation builder with Delphi source available. By Jordan Russell." >Inno Setup</a>, an awesome piece of customizable freeware for packaging up your add-in.</p>
<h2>Contents: How to Build an Excel Add-In</h2>
<ul style="margin-left: 24pt;">
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-1-basic-routine/"title="Build an Excel Add-In 1 – Basic Routine" >Build an Excel Add-In 1 – Basic Routine</a></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-2-enhanced-functionality/"title="Build an Excel Add-In 2 – Enhanced Functionality" >Build an Excel Add-In 2 – Enhanced Functionality</a></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-3-auxiliary-modular-functions/"title="Build an Excel Add-In 3 - Auxiliary Modular Functions" >Build an Excel Add-In 3 – Auxiliary Modular Functions</a></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-4-create-the-dialog/"title="Build an Excel Add-In 4 – Create the Dialog" >Build an Excel Add-In 4 – Create the Dialog</a></li>
<li><strong>Build an Excel Add-In 5 – Tie the Code Together</strong></li>
<li>Build an Excel Add-In 6 – Interface for 2003</li>
<li>Build an Excel Add-In 7 – Interface for 2007</li>
<li>Build an Excel Add-In 8 – Last Steps</li>
<li>Build an Excel Add-In 9 – Deployment</li>
</ul>
<p>Peltier Technical Services, Inc., Copyright © 2010.<br /> <br /><span style="font: 80% Verdana,Tahoma,Arial,sans-serif;">Licensed under a <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/" rel="nofollow" rel="license" >Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.<br /> <br />
<a href="http://www.exceluser.com/cmd.asp?Clk=1374689" rel="nofollow" ><IMG SRC="http://www.exceluser.com/images/info/pub/info_dash_c02.gif" ALT="Learn how to create Excel dashboards." WIDTH="468" HEIGHT="60" border=0></a><br />
<br /><img src="http://www.exceluser.com/cmd.asp?Imp=1374689" width="0" height="0" border="0"></p>



Bookmark and share this entry:


	<a rel="nofollow"  href="http://twitter.com/home?status=Build%20an%20Excel%20Add-In%205%20-%20Tie%20the%20Code%20Together%20-%20http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-5-tie-it-all-together%2F" title="Twitter"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-5-tie-it-all-together%2F&amp;title=Build%20an%20Excel%20Add-In%205%20-%20Tie%20the%20Code%20Together&amp;bodytext=This%20is%20the%20fifth%20in%20a%20series%20of%20posts%20that%20shows%20the%20steps%20involved%20in%20building%20an%20Excel%20add-in.%20In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20showed%20a%20VBA%20procedure%20that%20creates%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a" title="Digg"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-5-tie-it-all-together%2F&amp;t=Build%20an%20Excel%20Add-In%205%20-%20Tie%20the%20Code%20Together" title="Facebook"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-5-tie-it-all-together%2F&amp;title=Build%20an%20Excel%20Add-In%205%20-%20Tie%20the%20Code%20Together&amp;source=Peltier+Tech+Blog+Peltier+Tech+Excel+Charts+and+Programming+Blog&amp;summary=This%20is%20the%20fifth%20in%20a%20series%20of%20posts%20that%20shows%20the%20steps%20involved%20in%20building%20an%20Excel%20add-in.%20In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20showed%20a%20VBA%20procedure%20that%20creates%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a" title="LinkedIn"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-5-tie-it-all-together%2F&amp;title=Build%20an%20Excel%20Add-In%205%20-%20Tie%20the%20Code%20Together&amp;notes=This%20is%20the%20fifth%20in%20a%20series%20of%20posts%20that%20shows%20the%20steps%20involved%20in%20building%20an%20Excel%20add-in.%20In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20showed%20a%20VBA%20procedure%20that%20creates%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a" title="del.icio.us"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-5-tie-it-all-together%2F" title="Technorati"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-5-tie-it-all-together%2F&amp;title=Build%20an%20Excel%20Add-In%205%20-%20Tie%20the%20Code%20Together" title="StumbleUpon"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-5-tie-it-all-together%2F&amp;title=Build%20an%20Excel%20Add-In%205%20-%20Tie%20the%20Code%20Together&amp;annotation=This%20is%20the%20fifth%20in%20a%20series%20of%20posts%20that%20shows%20the%20steps%20involved%20in%20building%20an%20Excel%20add-in.%20In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20showed%20a%20VBA%20procedure%20that%20creates%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a" title="Google Bookmarks"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-5-tie-it-all-together%2F&amp;title=Build%20an%20Excel%20Add-In%205%20-%20Tie%20the%20Code%20Together" title="Reddit"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-5-tie-it-all-together%2F&amp;t=Build%20an%20Excel%20Add-In%205%20-%20Tie%20the%20Code%20Together" title="MySpace"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Build%20an%20Excel%20Add-In%205%20-%20Tie%20the%20Code%20Together&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-5-tie-it-all-together%2F" title="Slashdot"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-5-tie-it-all-together%2F&amp;submitHeadline=Build%20an%20Excel%20Add-In%205%20-%20Tie%20the%20Code%20Together&amp;submitSummary=This%20is%20the%20fifth%20in%20a%20series%20of%20posts%20that%20shows%20the%20steps%20involved%20in%20building%20an%20Excel%20add-in.%20In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20showed%20a%20VBA%20procedure%20that%20creates%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-5-tie-it-all-together%2F&amp;t=Build%20an%20Excel%20Add-In%205%20-%20Tie%20the%20Code%20Together&amp;s=This%20is%20the%20fifth%20in%20a%20series%20of%20posts%20that%20shows%20the%20steps%20involved%20in%20building%20an%20Excel%20add-in.%20In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20showed%20a%20VBA%20procedure%20that%20creates%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a" title="Tumblr"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://peltiertech.com/WordPress/build-an-excel-add-in-5-tie-it-all-together/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build an Excel Add-In 4 &#8211; Create the Dialog</title>
		<link>http://peltiertech.com/WordPress/build-an-excel-add-in-4-create-the-dialog/</link>
		<comments>http://peltiertech.com/WordPress/build-an-excel-add-in-4-create-the-dialog/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 08:00:54 +0000</pubDate>
		<dc:creator>Jon Peltier</dc:creator>
				<category><![CDATA[VBA]]></category>
		<category><![CDATA[Add-ins]]></category>

		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=2757</guid>
		<description><![CDATA[This is the fourth part of a series that shows the steps involved in building an Excel add-in. In Build an Excel Add-In 1 – Basic Routine I showed a VBA procedure that creates a regular chart from an arbitrary rectangular range, including from a pivot table. In Build an Excel Add-In 2 – Enhanced [...]]]></description>
			<content:encoded><![CDATA[<p>This is the fourth part of a series that shows the steps involved in building an Excel add-in. In <a href="../build-an-excel-add-in-1-basic-routine/" rel="nofollow" title="Build an Excel Add-In 1 – Basic Routine" >Build an Excel Add-In 1 – Basic Routine</a> I showed a VBA procedure that creates a regular chart from an arbitrary rectangular range, including from a pivot table. In <a href="../build-an-excel-add-in-2-enhanced-functionality/" rel="nofollow" title="Build an Excel Add-In 2 – Enhanced Functionality | PTS Blog" >Build an Excel Add-In 2 – Enhanced Functionality</a> I turned modularized this routine, so it could be called from any code that passed the appropriate settings into the function as arguments. In <a href="../build-an-excel-add-in-3-auxiliary-modular-functions/" rel="nofollow" title="Build an Excel Add-In 3 - Auxiliary Modular Functions" >Build an Excel Add-In 3 – Auxiliary Modular Functions</a> I included an additional modular function which cleans up the chart created in the previous article&#8217;s code. Because this function is widely useful, it will be made more general in a future article, after this series is finished.</p>
<p>In this installment of the<strong> Build an Excel Add-In</strong> series, I will show how to create a custom dialog using a VBA UserForm, a set of controls, and related code.</p>
<h2><span id="more-2757"></span>Insert UserForm</h2>
<p>The first step in building a dialog is to insert a UserForm. In the Visual Basic Editor (VBE) select the project in the Project Explorer pane, then from the Insert menu, choose UserForm.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_InsertUserForm.png" alt="Insert UserFrom from Menu" /></p>
<p>A new window is created, containing a blank UserForm.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_UserForm1.png" alt="New UserFrom" /></p>
<p>The UserForm is listed in the Project Explorer, in the Forms folder of the VB Project.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_ProjExplorer_UserForm1.png" alt="UserFrom Listed in the Project Explorer" /></p>
<p>A UserForm actually consists of two parts: the Designer window and the Code window. The code window contains all of the VBA procedures that make the dialog work. For example, in the code window you will find the code that responds to button clicks.</p>
<p>When the UserForm&#8217;s window is active, the Properties window can be used to edit the properties of the UserForm. For example, the name of the UserForm has been changed from UserForm1 (below left) to FPlotSetup (below right), and the caption has been changed from UserForm1 to PT Plotter.</p>
<p style="text-align: center;"><img src="http://peltiertech.com/images/2010-01/PTPlot_Properties_UserForm.png" alt="Properties of the Original UserForm" /> <span style="color: #ffffff;">- -</span> <img src="http://peltiertech.com/images/2010-01/PTPlot_Properties_FPlotSetup.png" alt="Properties of the Renamed UserForm" /></p>
<p>In addition to changing properties through the Properties window, the size of the dialog can be changed by dragging the white handles on the right and bottom edge of the UserForm.</p>
<h2>Forms Controls</h2>
<p>The blank UserForm shown above is transformed into the fully featured dialog shown below by adding and coding a set of controls. VBA offers a range of controls, and others can be used if additional capabilities are required. Care should be taken when using controls which are not built in, because of potential deployment complications.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_AddInDialog.png" alt="Finished Add-In Dialog" /></p>
<p>The controls in this dialog are listed below, in top-down and left-to-right order:</p>
<ul style="margin-left: 24pt;">
<li>lblChartData</li>
<li>refChartData</li>
<li>fraOrientation
<ul style="margin-left: 12pt; margin-bottom: 0;">
<li>optByRow</li>
<li>optByColumn</li>
</ul>
</li>
<li>fraHeaders
<ul style="margin-left: 12pt; margin-bottom: 0;">
<li>txtHeaderRows</li>
<li>lblHeaderRows</li>
<li>txtHeaderColumns</li>
<li> lblHeaderColumns</li>
</ul>
</li>
<li>fraChartType
<ul style="margin-left: 12pt; margin-bottom: 0;">
<li>optChartTypeXY</li>
<li>optChartTypeLine</li>
<li> optChartTypeBar</li>
<li>optChartTypeColumn</li>
</ul>
</li>
<li>lblChartPosition</li>
<li>refChartPosition</li>
<li>lblChartPosition2</li>
<li>lblCopyright</li>
<li>btnOK</li>
<li>btnCancel</li>
</ul>
<p>I have used a simple naming convention:</p>
<p>Three letter prefixes identify the type of control: <em>lbl</em> for label, <em>ref</em> for RefEdit, <em>fra</em> for frame, <em>opt</em> for option button, <em>txt</em> for text boxes, <em>btn</em> for command buttons (some developers use <em>cmd</em> for command button, but I think <em>btn</em> is more descriptive)). Not used in this dialog are <em>chk</em> for check box, <em>mpg</em> for multipage, <em>lst</em> for list box, <em>cbo</em> for combo box, <em>scr</em> for scroll bar, <em>spn</em> for spin button, <em>img</em> for image.</p>
<p>The purpose of each control is encoded into its name. For example, optChartTypeXY is for choosing the XY Chart Type option, refChartData is the RefEdit used to select the chart data, etc.</p>
<h2>Controls Toolbox</h2>
<p>When a UserForm is the active window, the Controls Toolbox appears. This is a toolbar-like window that contains VBA controls as well as other controls that you may have added.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_ControlsToolbox.png" alt="Controls Toolbox" /></p>
<p>To add a control to the dialog, click on its icon in the Controls Toolbox. When the cursor is moved over the UserForm, it changes to a cross hair and the selected icon is shown below the icon to remind you what control you&#8217;re adding. Click and drag to draw a rectangle as large as the control you are adding.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_AddingControl.png" alt="Adding a Control to a UserForm" /></p>
<p>When you release the mouse, the control appears, highlighted with white resizing handles.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_AddedControl.png" alt="Control Added to a UserForm" /></p>
<p>After a control is added, its name and other properties can be set in the Property window, just as the name and caption of the UserForm itself were set.</p>
<h2>Labels and Text Boxes</h2>
<p>Labels simply contain text that guides the user through the dialog. The user cannot change the caption of a label, but the caption can be controlled by code in response to certain conditions.</p>
<p>Text boxes allow a user to specify values which can be represented as text. These values may be numerical, but it is up to the programmer to deal with number formats of entered and displayed numbers. In our dialog, text boxes are used to specify the number of header rows and columns in the chart source data.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_LabelAndTextBox.png" alt="Label and Text Box" /></p>
<h2>Frames</h2>
<p>Frames are used to give some order to the dialog, grouping together related controls. Our dialog has three frames, containing controls for selection of data orientation, header rows and columns, and chart type.</p>
<h2>Option Buttons and Checkboxes</h2>
<p>Option buttons are used to let a user select from among several options. All option buttons within a frame or with the same GroupName property are grouped together, such that only one can be true (selected) at once, and changing one to true automatically changes the others in its group to false. In this frame, only the XY option is selected.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_fraChartTypeXY.png" alt="Chart Type Frame with XY Option Selected" /></p>
<p>When the Line option is selected, the XY option is unselected.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_fraChartTypeLine.png" alt="Chart Type Frame with Line Option Selected" /></p>
<p>Check boxes are used to let a user set a true (checked) or false (unchecked) value. In the absence of event code in the UserForm, check box values are independent of each other.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_Checkboxes.png" alt="UserForm Check Boxes" /></p>
<h2>List Boxes and Combo Boxes</h2>
<p>List boxes and combo boxes allow the user to select one or more items from a list. A list box is more user friendly because it shows the whole list (or at least a subset of the list) while the combo box only shows the selected item, unless the user clicks to expand the list.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_ListAndComboBoxes.png" alt="List Box, Combo Box, and Expanded Combo Box" /></p>
<h2>Command Buttons</h2>
<p>Command Buttons allow a user to initiate an action, in our case, approving or canceling the session with the dialog. Clicking the button runs code that carries out the user&#8217;s command.</p>
<h2>RefEdit Controls</h2>
<p>RefEdit controls allow the user to select a range of cells with the mouse. While the user is selecting cells, the UserForm shrinks to the size of the RefEdit plus the title bar. The address of the selected range appears in the RefEdit and updates as the mouse is dragged, and the size of the selected range is displayed next to the cursor.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_RefEditSelecting.png" alt="RefEdit in Minimized Dialog While Range is Selected" /></p>
<p>When the mouse is released, the UserForm returns to its original size, and the address remains in the RefEdit.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_RefEditSelected.png" alt="RefEdit Shows Address of Selected=" /></p>
<p>Read more about the RefEdit control in <a href="http://peltiertech.com/WordPress/using-refedit-controls-in-excel-dialogs/"title="Using RefEdit Controls in Excel Dialogs » PTS Blog" >Using RefEdit Controls in Excel Dialogs</a>.</p>
<h2>Adding Code</h2>
<p>There is a simple way to add code to the UserForm. Double click on a control, and the UserForm&#8217;s code window opens. An empty event procedure for the default method (action) of the control is added to the code window. For example, double clicking on the OK button adds the <tt class="tt">btnOK_Click</tt> event procedure stub to the code.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_btnOK_Code.png" alt="OK Button Click Event Procedure" /></p>
<p>You enter the code you want to run on the OK button click event into this procedure stub. The following shows a call to a function that validates the user&#8217;s selections. If selections are valid, the code hides the form, sending execution back to the procedure that showed the UserForm. If selections are invalid, the user sees a message and decides whether to continue or bail out.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_btnOK_Click.png" alt="OK Button Click Event Procedure" /></p>
<p>Notice the two dropdowns at the top of the code window. The selected control, btnOK, is shown in the left dropdown, and the Click event is shown in the right dropdown. You can use these dropdowns to select any event that&#8217;s available for any control. It&#8217;s a good idea to use these dropdowns to define your procedures, because some events include arguments, and the dropdowns will always get the arguments correct.</p>
<p>For example, the KeyDown event of a text box control includes the KeyCode (the ASCII code of the key that was pressed) and the Shift (whether Shift, Alt, and/or Ctrl were down when the key was pressed) arguments. When the procedure runs, Excel passes these values into the procedure, so the code knows which key was pressed, under which shift state.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_txtHdrRows_KeyDown.png" alt="Header Rows Textbox KeyDown Event Procedure" /></p>
<p>The UserForm code module can contain event procedures, as well as functions and subs that can be called by these event procedures. For example, the <tt class="tt">Validated</tt> function called by the <tt class="tt">btnOK_Click</tt> event is also found in the UserForm&#8217;s code. Procedures in the UserForm can also call procedures in other modules.</p>
<h2>The Code Behind the Dialog</h2>
<p>The complete listing of the Userform&#8217;s code is presented below.</p>
<p>The <tt class="tt">UserForm_Initialize</tt> event loads the selected range address into the RefEdit.</p>
<p>The <tt class="tt">Validated</tt> function checks the RefEdit for a valid range and the header text boxes for valid numbers of header rows and columns.</p>
<p>The various property procedures are used called by the main routine to extract information from the UserForm. I wrote about this technique in <a href="http://peltiertech.com/Excel/PropertyProcedures.html" rel="nofollow" title="Property Procedures - Passing Information to and from Forms" >Property Procedures &#8211; Passing Information to and from Forms</a>.</p>
<p>The <tt class="tt">mbCancel</tt> variable is True if the Cancel button is clicked. The <tt class="tt">Cancel</tt> property checks this variable and tells the main routine if the user canceled the dialog.</p>
<pre class="vbasmall"><code>Option Explicit

Private mbCancel As Boolean

Private Sub btnCancel_Click()
  mbCancel = True
  Me.Hide
End Sub

Private Sub btnOK_Click()
  Dim sMessage As String
  Dim lResponse As VbMsgBoxResult

  If Validated(sMessage) Then
    mbCancel = False
    Me.Hide
  Else
    lResponse = MsgBox(sMessage, vbRetryCancel, "Invalid Information")
    If lResponse = vbCancel Then
      btnCancel_Click
    End If
  End If
End Sub

Public Property Get Cancel() As Boolean
  Cancel = mbCancel
End Property

Public Property Get DataOrientation() As XlRowCol
  Select Case True
    Case Me.optByColumn.Value
      DataOrientation = xlColumns
    Case Me.optByRow.Value
      DataOrientation = xlRows
  End Select
End Property

Public Property Get HeaderRows() As Long
  HeaderRows = Val(Me.txtHeaderRows.Text)
End Property

Public Property Get HeaderColumns() As Long
  HeaderColumns = Val(Me.txtHeaderColumns.Text)
End Property

Public Property Get ChartType() As XlChartType
  Select Case True
    Case Me.optChartTypeXY.Value
      ChartType = xlXYScatterLines
    Case Me.optChartTypeLine.Value
      ChartType = xlLineMarkers
    Case Me.optChartTypeBar.Value
      ChartType = xlBarClustered
    Case Me.optChartTypeColumn.Value
      ChartType = xlColumnClustered
  End Select
End Property

Public Property Get ChartDataRange() As Range
  Set ChartDataRange = Range(Me.refChartData.Text)
End Property

Public Property Get ChartPosition() As Range
  On Error Resume Next
  Set ChartPosition = Range(Me.refChartPosition.Text)
  On Error GoTo 0
End Property

Private Function Validated(sMsg As String) As Boolean

  ' Minimalist input validation

  Dim rTest As Range
  Dim iTest As Long

  Validated = True

  On Error Resume Next
  Set rTest = Range(Me.refChartData.Text)
  On Error GoTo 0
  If rTest Is Nothing Then
    Validated = False
    sMsg = "Invalid data range selected."
    GoTo ExitFunction
  End If

  iTest = Me.HeaderRows
  If iTest &gt;= rTest.Rows.Count Then
    Validated = False
    sMsg = "Too many header rows specified."
    GoTo ExitFunction
  End If
  iTest = Me.HeaderColumns
  If iTest &gt;= rTest.Columns.Count Then
    Validated = False
    If Len(sMsg) &gt; 0 Then sMsg = sMsg &amp; vbNewLine
    sMsg = sMsg &amp; "Too many header columns specified."
    GoTo ExitFunction
  End If

ExitFunction:

End Function

Private Sub UserForm_Initialize()

  ' Define current range for RefEdit, if applicable

  Dim sAddress As String
  If TypeName(Selection) = "Range" Then
    If Selection.Cells.Count = 1 Then
      sAddress = Selection.CurrentRegion.Address(External:=True)
    Else
      sAddress = Selection.Address(External:=True)
    End If
    sAddress = Mid$(sAddress, InStr(sAddress, "]") + 1)
    If InStr(sAddress, "'") &gt; 0 Then
      sAddress = "'" &amp; sAddress
    End If
    Me.refChartData.Text = sAddress
  End If
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  If CloseMode = vbFormControlMenu Then
    Cancel = True
    btnCancel_Click
  End If
End Sub</code></pre>
<p>In the next article of the series, <strong>Build an Excel Add-In 5 – Tie the Code Together</strong>, we will develop code to call this dialog, extract the user selections, and produce a chart using these settings.</p>
<h2>Contents: How to Build an Excel Add-In</h2>
<ul style="margin-left: 24pt;">
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-1-basic-routine/"title="Build an Excel Add-In 1 – Basic Routine" >Build an Excel Add-In 1 – Basic Routine</a></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-2-enhanced-functionality/"title="Build an Excel Add-In 2 – Enhanced Functionality" >Build an Excel Add-In 2 – Enhanced Functionality</a></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-3-auxiliary-modular-functions/"title="Build an Excel Add-In 3 - Auxiliary Modular Functions" >Build an Excel Add-In 3 – Auxiliary Modular Functions</a></li>
<li><strong>Build an Excel Add-In 4 – Create the Dialog</strong></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-5-tie-it-all-together/"title="Build an Excel Add-In 5 – Tie the Code Together" >Build an Excel Add-In 5 – Tie the Code Together</a></li>
<li>Build an Excel Add-In 6 – Interface for 2003</li>
<li>Build an Excel Add-In 7 – Interface for 2007</li>
<li>Build an Excel Add-In 8 – Last Steps</li>
<li>Build an Excel Add-In 9 – Deployment</li>
</ul>
<p>Peltier Technical Services, Inc., Copyright © 2010.<br /> <br /><span style="font: 80% Verdana,Tahoma,Arial,sans-serif;">Licensed under a <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/" rel="nofollow" rel="license" >Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.<br /> <br />
<a href="http://www.exceluser.com/cmd.asp?Clk=1374689" rel="nofollow" ><IMG SRC="http://www.exceluser.com/images/info/pub/info_dash_c02.gif" ALT="Learn how to create Excel dashboards." WIDTH="468" HEIGHT="60" border=0></a><br />
<br /><img src="http://www.exceluser.com/cmd.asp?Imp=1374689" width="0" height="0" border="0"></p>



Bookmark and share this entry:


	<a rel="nofollow"  href="http://twitter.com/home?status=Build%20an%20Excel%20Add-In%204%20-%20Create%20the%20Dialog%20-%20http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-4-create-the-dialog%2F" title="Twitter"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-4-create-the-dialog%2F&amp;title=Build%20an%20Excel%20Add-In%204%20-%20Create%20the%20Dialog&amp;bodytext=This%20is%20the%20fourth%20part%20of%20a%20series%20that%20shows%20the%20steps%20involved%20in%20building%20an%20Excel%20add-in.%20In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20showed%20a%20VBA%20procedure%20that%20creates%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pi" title="Digg"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-4-create-the-dialog%2F&amp;t=Build%20an%20Excel%20Add-In%204%20-%20Create%20the%20Dialog" title="Facebook"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-4-create-the-dialog%2F&amp;title=Build%20an%20Excel%20Add-In%204%20-%20Create%20the%20Dialog&amp;source=Peltier+Tech+Blog+Peltier+Tech+Excel+Charts+and+Programming+Blog&amp;summary=This%20is%20the%20fourth%20part%20of%20a%20series%20that%20shows%20the%20steps%20involved%20in%20building%20an%20Excel%20add-in.%20In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20showed%20a%20VBA%20procedure%20that%20creates%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pi" title="LinkedIn"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-4-create-the-dialog%2F&amp;title=Build%20an%20Excel%20Add-In%204%20-%20Create%20the%20Dialog&amp;notes=This%20is%20the%20fourth%20part%20of%20a%20series%20that%20shows%20the%20steps%20involved%20in%20building%20an%20Excel%20add-in.%20In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20showed%20a%20VBA%20procedure%20that%20creates%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pi" title="del.icio.us"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-4-create-the-dialog%2F" title="Technorati"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-4-create-the-dialog%2F&amp;title=Build%20an%20Excel%20Add-In%204%20-%20Create%20the%20Dialog" title="StumbleUpon"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-4-create-the-dialog%2F&amp;title=Build%20an%20Excel%20Add-In%204%20-%20Create%20the%20Dialog&amp;annotation=This%20is%20the%20fourth%20part%20of%20a%20series%20that%20shows%20the%20steps%20involved%20in%20building%20an%20Excel%20add-in.%20In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20showed%20a%20VBA%20procedure%20that%20creates%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pi" title="Google Bookmarks"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-4-create-the-dialog%2F&amp;title=Build%20an%20Excel%20Add-In%204%20-%20Create%20the%20Dialog" title="Reddit"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-4-create-the-dialog%2F&amp;t=Build%20an%20Excel%20Add-In%204%20-%20Create%20the%20Dialog" title="MySpace"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Build%20an%20Excel%20Add-In%204%20-%20Create%20the%20Dialog&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-4-create-the-dialog%2F" title="Slashdot"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-4-create-the-dialog%2F&amp;submitHeadline=Build%20an%20Excel%20Add-In%204%20-%20Create%20the%20Dialog&amp;submitSummary=This%20is%20the%20fourth%20part%20of%20a%20series%20that%20shows%20the%20steps%20involved%20in%20building%20an%20Excel%20add-in.%20In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20showed%20a%20VBA%20procedure%20that%20creates%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pi&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-4-create-the-dialog%2F&amp;t=Build%20an%20Excel%20Add-In%204%20-%20Create%20the%20Dialog&amp;s=This%20is%20the%20fourth%20part%20of%20a%20series%20that%20shows%20the%20steps%20involved%20in%20building%20an%20Excel%20add-in.%20In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20showed%20a%20VBA%20procedure%20that%20creates%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pi" title="Tumblr"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://peltiertech.com/WordPress/build-an-excel-add-in-4-create-the-dialog/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Using RefEdit Controls in Excel Dialogs</title>
		<link>http://peltiertech.com/WordPress/using-refedit-controls-in-excel-dialogs/</link>
		<comments>http://peltiertech.com/WordPress/using-refedit-controls-in-excel-dialogs/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 07:00:34 +0000</pubDate>
		<dc:creator>Jon Peltier</dc:creator>
				<category><![CDATA[VBA]]></category>
		<category><![CDATA[RefEdit]]></category>

		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=2924</guid>
		<description><![CDATA[RefEdit Controls
RefEdit controls allow the user to select a range of cells with the mouse. While the user is selecting cells, the parent UserForm shrinks to the size of the RefEdit plus the title bar. The address of the selected range appears in the RefEdit and updates as the mouse is dragged, and the size [...]]]></description>
			<content:encoded><![CDATA[<h2>RefEdit Controls</h2>
<p>RefEdit controls allow the user to select a range of cells with the mouse. While the user is selecting cells, the parent UserForm shrinks to the size of the RefEdit plus the title bar. The address of the selected range appears in the RefEdit and updates as the mouse is dragged, and the size of the selected range is displayed next to the cursor.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_RefEditSelecting.png" alt="RefEdit in Minimized Dialog While Range is Selected" /></p>
<p><span id="more-2924"></span>When the mouse is released, the UserForm returns to its original size, and the address remains in the RefEdit. When the RefEdit has focus, the indicated range is highlighted with the &#8220;marching ants&#8221; border.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_RefEditSelected.png" alt="RefEdit Shows Address of Selected=" /></p>
<p>The RefEdit actually contains a string variable, not a range. This allows the user to edit the address in the RefEdit, and in fact, the user can enter any text as if the RefEdit is a text box. This also allows the programmer to insert the address of a range (usually the current selection) into the RefEdit when loading the UserForm.</p>
<p>The Error Bar Utility that I introduced in <a href="http://peltiertech.com/WordPress/error-bars-in-excel-2007/"title="Error Bars in Excel 2007 Charts » PTS Blog" >Error Bars in Excel 2007 Charts</a> makes use of this dual entry behavior, allowing a user to enter a constant or a range of cells for the error bar values.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2008-12/errXYdialog2.png" alt="" /></p>
<h2>RefEdit Irregularities</h2>
<p>The RefEdit control has some strange and wonderful idiosyncrasies which must be considered when designing a dialog. There are (at least) four issues that are important to keep in mind.</p>
<p><strong>RefEdits must be placed directly on the UserForm itself.</strong> If you put a RefEdit in a frame or on a multipage, strange things will happen, including bizarre Excel crashes.</p>
<p><strong>RefEdits must not be used on modeless forms.</strong> RefEdits on modeless forms will result in bizarre Excel crashes.</p>
<p><strong>RefEdit event procedures should be avoided.</strong> RefEdit events do not behave reliably, and they may result in VBA errors which are difficult to debug.</p>
<p><strong>References to RefEdits must be removed.</strong> When a UserForm is added to a VB project, Excel adds a reference to the Microsoft Forms 2.0 Object Library. This reference is required for proper operation of the UserForms in your project. <em>To see what references your project has, select the project in the Project Explorer, then select References from the Tools menu.</em></p>
<p>When a RefEdit is added to a UserForm, Excel sometimes adds a reference to the Ref Edit Control. This was fine in earlier versions of Excel, but there appear to be incompatibilities in recent versions of the RefEdit library. These problems often are associated with an <a href="http://peltiertech.com/WordPress/unspecified-painfully-frustrating-error/"title="Unspecified but Painfully Frustrating Error » PTS Blog" >Unspecified but Painfully Frustrating Error</a>.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlot_References.png" alt="VBA References" /></p>
<p>To reduce the risk of RefEdit-related issues, you should uncheck the box in front of Ref Edit Control in the References dialog. Otherwise, there may be problems loading the add-in on another user’s machine, including the removal of RefEdits from the dialogs and other bizarre behavior.</p>
<p>It is also helpful to process the workbook or add-in&#8217;s code through an earlier version of Excel. I use a VM with Office 2000 installed on it for this purpose. Open Excel 2000, open the workbook or add-in, run Rob Bovey&#8217;s free <a href="http://www.appspro.com/Utilities/CodeCleaner.htm" rel="nofollow" title="Code Cleaner from Applications Professionals" >Code Cleaner</a> application, then compile the code and save the file.</p>
<p>It may also be necessary to remove RefEdit.exd files from a user’s computer if problems occur and unchecking the reference doesn’t fix them. these exd files are temporary files that contain instructions Excel uses to build RefEdits, and the exd may conflict with the RefEdits in the workbook. If this doesn’t work, the next step is to run Detect and Repair on Excel, then reinstall Office, then sacrifice the computer at the next full moon.</p>
<p>Peltier Technical Services, Inc., Copyright © 2010.<br /> <br /><span style="font: 80% Verdana,Tahoma,Arial,sans-serif;">Licensed under a <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/" rel="nofollow" rel="license" >Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.<br /> <br />
<a href="http://www.exceluser.com/cmd.asp?Clk=1374689" rel="nofollow" ><IMG SRC="http://www.exceluser.com/images/info/pub/info_dash_c02.gif" ALT="Learn how to create Excel dashboards." WIDTH="468" HEIGHT="60" border=0></a><br />
<br /><img src="http://www.exceluser.com/cmd.asp?Imp=1374689" width="0" height="0" border="0"></p>



Bookmark and share this entry:


	<a rel="nofollow"  href="http://twitter.com/home?status=Using%20RefEdit%20Controls%20in%20Excel%20Dialogs%20-%20http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fusing-refedit-controls-in-excel-dialogs%2F" title="Twitter"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fusing-refedit-controls-in-excel-dialogs%2F&amp;title=Using%20RefEdit%20Controls%20in%20Excel%20Dialogs&amp;bodytext=RefEdit%20Controls%0D%0A%0D%0ARefEdit%20controls%20allow%20the%20user%20to%20select%20a%20range%20of%20cells%20with%20the%20mouse.%20While%20the%20user%20is%20selecting%20cells%2C%20the%20parent%20UserForm%20shrinks%20to%20the%20size%20of%20the%20RefEdit%20plus%20the%20title%20bar.%20The%20address%20of%20the%20selected%20range%20appears%20in%20" title="Digg"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fusing-refedit-controls-in-excel-dialogs%2F&amp;t=Using%20RefEdit%20Controls%20in%20Excel%20Dialogs" title="Facebook"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fusing-refedit-controls-in-excel-dialogs%2F&amp;title=Using%20RefEdit%20Controls%20in%20Excel%20Dialogs&amp;source=Peltier+Tech+Blog+Peltier+Tech+Excel+Charts+and+Programming+Blog&amp;summary=RefEdit%20Controls%0D%0A%0D%0ARefEdit%20controls%20allow%20the%20user%20to%20select%20a%20range%20of%20cells%20with%20the%20mouse.%20While%20the%20user%20is%20selecting%20cells%2C%20the%20parent%20UserForm%20shrinks%20to%20the%20size%20of%20the%20RefEdit%20plus%20the%20title%20bar.%20The%20address%20of%20the%20selected%20range%20appears%20in%20" title="LinkedIn"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fusing-refedit-controls-in-excel-dialogs%2F&amp;title=Using%20RefEdit%20Controls%20in%20Excel%20Dialogs&amp;notes=RefEdit%20Controls%0D%0A%0D%0ARefEdit%20controls%20allow%20the%20user%20to%20select%20a%20range%20of%20cells%20with%20the%20mouse.%20While%20the%20user%20is%20selecting%20cells%2C%20the%20parent%20UserForm%20shrinks%20to%20the%20size%20of%20the%20RefEdit%20plus%20the%20title%20bar.%20The%20address%20of%20the%20selected%20range%20appears%20in%20" title="del.icio.us"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fusing-refedit-controls-in-excel-dialogs%2F" title="Technorati"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fusing-refedit-controls-in-excel-dialogs%2F&amp;title=Using%20RefEdit%20Controls%20in%20Excel%20Dialogs" title="StumbleUpon"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fusing-refedit-controls-in-excel-dialogs%2F&amp;title=Using%20RefEdit%20Controls%20in%20Excel%20Dialogs&amp;annotation=RefEdit%20Controls%0D%0A%0D%0ARefEdit%20controls%20allow%20the%20user%20to%20select%20a%20range%20of%20cells%20with%20the%20mouse.%20While%20the%20user%20is%20selecting%20cells%2C%20the%20parent%20UserForm%20shrinks%20to%20the%20size%20of%20the%20RefEdit%20plus%20the%20title%20bar.%20The%20address%20of%20the%20selected%20range%20appears%20in%20" title="Google Bookmarks"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fusing-refedit-controls-in-excel-dialogs%2F&amp;title=Using%20RefEdit%20Controls%20in%20Excel%20Dialogs" title="Reddit"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fusing-refedit-controls-in-excel-dialogs%2F&amp;t=Using%20RefEdit%20Controls%20in%20Excel%20Dialogs" title="MySpace"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Using%20RefEdit%20Controls%20in%20Excel%20Dialogs&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fusing-refedit-controls-in-excel-dialogs%2F" title="Slashdot"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fusing-refedit-controls-in-excel-dialogs%2F&amp;submitHeadline=Using%20RefEdit%20Controls%20in%20Excel%20Dialogs&amp;submitSummary=RefEdit%20Controls%0D%0A%0D%0ARefEdit%20controls%20allow%20the%20user%20to%20select%20a%20range%20of%20cells%20with%20the%20mouse.%20While%20the%20user%20is%20selecting%20cells%2C%20the%20parent%20UserForm%20shrinks%20to%20the%20size%20of%20the%20RefEdit%20plus%20the%20title%20bar.%20The%20address%20of%20the%20selected%20range%20appears%20in%20&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fusing-refedit-controls-in-excel-dialogs%2F&amp;t=Using%20RefEdit%20Controls%20in%20Excel%20Dialogs&amp;s=RefEdit%20Controls%0D%0A%0D%0ARefEdit%20controls%20allow%20the%20user%20to%20select%20a%20range%20of%20cells%20with%20the%20mouse.%20While%20the%20user%20is%20selecting%20cells%2C%20the%20parent%20UserForm%20shrinks%20to%20the%20size%20of%20the%20RefEdit%20plus%20the%20title%20bar.%20The%20address%20of%20the%20selected%20range%20appears%20in%20" title="Tumblr"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://peltiertech.com/WordPress/using-refedit-controls-in-excel-dialogs/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Build an Excel Add-In 3 &#8211; Auxiliary Modular Functions</title>
		<link>http://peltiertech.com/WordPress/build-an-excel-add-in-3-auxiliary-modular-functions/</link>
		<comments>http://peltiertech.com/WordPress/build-an-excel-add-in-3-auxiliary-modular-functions/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 08:00:09 +0000</pubDate>
		<dc:creator>Jon Peltier</dc:creator>
				<category><![CDATA[VBA]]></category>
		<category><![CDATA[Add-ins]]></category>

		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=2755</guid>
		<description><![CDATA[In Build an Excel Add-In 1 – Basic Routine I coded a procedure in VBA to create a regular chart from an arbitrary rectangular range, including from a pivot table. In Build an Excel Add-In 2 – Enhanced Functionality I turned this routine into a modular function, that could be called from any code which [...]]]></description>
			<content:encoded><![CDATA[<p style="margin-bottom: 12px;">In <a href="../build-an-excel-add-in-1-basic-routine/" rel="nofollow" title="Build an Excel Add-In 1 – Basic Routine" >Build an Excel Add-In 1 – Basic Routine</a> I coded a procedure in VBA to create a regular chart from an arbitrary rectangular range, including from a pivot table. In <a href="http://peltiertech.com/WordPress/build-an-excel-add-in-2-enhanced-functionality/"title="Build an Excel Add-In 2 – Enhanced Functionality | PTS Blog" >Build an Excel Add-In 2 – Enhanced Functionality</a> I turned this routine into a modular function, that could be called from any code which passed in the appropriate settings as arguments to the function.</p>
<p style="margin-bottom: 12px;">In this post I present an example of another modular function. I say &#8220;modular&#8221; because the function is not integrated into any other code, and thus can be called from any procedure that needs its functionality.</p>
<p style="margin-bottom: 12px;">One big advantage of modular functions like this is that they can be called from many other procedures, and each time they execute the same way. If I want to make an adjustment to the function, I can make the change in one place, and the change is reflected every time it is run.</p>
<p style="margin-bottom: 12px;">Another advantage of such modular functions is that they can be copied from one project and pasted into another, and you don&#8217;t have to carry out extensive testing to make sure that it works. A quick run through the code is usually sufficient to ensure proper execution.</p>
<h2><span id="more-2755"></span>The New Function</h2>
<p>This rudimentary function is still a very useful one. It takes a chart as its sole argument, applies some formatting to the chart, then returns the chart as its value.</p>
<p>Given a chart variable called TheChart, the function is called like this:</p>
<pre class="vbasmall"><code>Set TheChart = CleanUpChart(TheChart)</code></pre>
<p>The function removes the borders on the chart area, plot area, and legend. It applies a uniform, non-auto-scaling font to all text elements. It removes borders on bar and column chart series and changes the gap spacing to 100%. It also widens the plot area to redue the wasted white space around the chart.</p>
<p>Here is the function in all of its glory. Feel free to adapt it to your own needs, using your own preferred formatting.</p>
<p>An alternate version of this function may convert 3D charts to their 2D equivalents, for example.</p>
<pre class="vbasmall"><code>Function CleanUpChart(cht As Chart) As Chart

  <span style="color: #339966;">' PRETTIFY THIS CHART
  ' ' chart area: remove border, fix font size, disable font autoscaling
  ' ' legend: remove border, resize, reposition
  ' ' plot area: remove border and fill, maximize size, minimize margins
  ' ' gridlines: remove
</span>
  Dim dLgndWidth As Double
  Dim iLgndEntry As Long
  Dim iAxType As XlAxisType
  Dim iAxGroup As XlAxisGroup
  Dim iSrs As Long
  Dim bScreenUpdating As Boolean

  bScreenUpdating = Application.ScreenUpdating
  Application.ScreenUpdating = False

  With cht
    With .ChartArea
      .Border.LineStyle = xlNone
      .AutoScaleFont = False
      .Font.Size = 8
    End With
    With .Legend
      .Border.LineStyle = xlNone
      .Left = 0
      .Width = cht.ChartArea.Width
      dLgndWidth = .LegendEntries(1).Width
      For iLgndEntry = 2 To .LegendEntries.Count
        If dLgndWidth &lt; .LegendEntries(iLgndEntry).Width Then
          dLgndWidth = .LegendEntries(iLgndEntry).Width
        End If
      Next
      .Width = dLgndWidth
      .Left = cht.ChartArea.Width
    End With
    With .PlotArea
      .Border.LineStyle = xlNone
      .Interior.ColorIndex = xlNone
      .Top = 0
      .Left = 0
      .Height = cht.ChartArea.Height
      .Width = cht.Legend.Left - 2
    End With
    For iAxGroup = xlPrimary To xlSecondary
      For iAxType = xlCategory To xlValue
        If .HasAxis(iAxType, iAxGroup) Then
          If .Axes(iAxType, iAxGroup).HasMajorGridlines Then
            .Axes(iAxType, iAxGroup).MajorGridlines.Delete
          End If
          If .Axes(iAxType, iAxGroup).HasMinorGridlines Then
            .Axes(iAxType, iAxGroup).MinorGridlines.Delete
          End If
        End If
      Next
    Next
    If .ChartType = xlColumnClustered Or .ChartType = xlBarClustered Then
      .ChartGroups(1).GapWidth = 100
      For iSrs = 1 To .SeriesCollection.Count
        .SeriesCollection(iSrs).Border.LineStyle = xlNone
      Next
    End If

  End With

  Set CleanUpChart = cht

  Application.ScreenUpdating = bScreenUpdating

End Function</code></pre>
<h2>Contents: How to Build an Excel Add-In</h2>
<ul style="margin-left: 24pt;">
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-1-basic-routine/"title="Build an Excel Add-In 1 – Basic Routine" >Build an Excel Add-In 1 – Basic Routine</a></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-2-enhanced-functionality/"title="Build an Excel Add-In 2 – Enhanced Functionality" >Build an Excel Add-In 2 – Enhanced Functionality</a></li>
<li><strong>Build an Excel Add-In 3 – Auxiliary Modular Functions</strong></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-4-create-the-dialog/"title="Build an Excel Add-In 4 – Create the Dialog" >Build an Excel Add-In 4 – Create the Dialog</a></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-5-tie-it-all-together/"title="Build an Excel Add-In 5 – Tie the Code Together" >Build an Excel Add-In 5 – Tie the Code Together</a></li>
<li>Build an Excel Add-In 6 – Interface for 2003</li>
<li>Build an Excel Add-In 7 – Interface for 2007</li>
<li>Build an Excel Add-In 8 – Last Steps</li>
<li>Build an Excel Add-In 9 – Deployment</li>
</ul>
<p>Peltier Technical Services, Inc., Copyright © 2010.<br /> <br /><span style="font: 80% Verdana,Tahoma,Arial,sans-serif;">Licensed under a <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/" rel="nofollow" rel="license" >Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.<br /> <br />
<a href="http://www.exceluser.com/cmd.asp?Clk=1374689" rel="nofollow" ><IMG SRC="http://www.exceluser.com/images/info/pub/info_dash_c02.gif" ALT="Learn how to create Excel dashboards." WIDTH="468" HEIGHT="60" border=0></a><br />
<br /><img src="http://www.exceluser.com/cmd.asp?Imp=1374689" width="0" height="0" border="0"></p>



Bookmark and share this entry:


	<a rel="nofollow"  href="http://twitter.com/home?status=Build%20an%20Excel%20Add-In%203%20-%20Auxiliary%20Modular%20Functions%20-%20http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-3-auxiliary-modular-functions%2F" title="Twitter"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-3-auxiliary-modular-functions%2F&amp;title=Build%20an%20Excel%20Add-In%203%20-%20Auxiliary%20Modular%20Functions&amp;bodytext=In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20coded%20a%20procedure%20in%20VBA%20to%20create%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pivot%20table.%20In%20Build%20an%20Excel%20Add-In%202%20%E2%80%93%20Enhanced%20Functionality%20I%20turned%20this%20routine%20into%20a%20mo" title="Digg"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-3-auxiliary-modular-functions%2F&amp;t=Build%20an%20Excel%20Add-In%203%20-%20Auxiliary%20Modular%20Functions" title="Facebook"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-3-auxiliary-modular-functions%2F&amp;title=Build%20an%20Excel%20Add-In%203%20-%20Auxiliary%20Modular%20Functions&amp;source=Peltier+Tech+Blog+Peltier+Tech+Excel+Charts+and+Programming+Blog&amp;summary=In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20coded%20a%20procedure%20in%20VBA%20to%20create%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pivot%20table.%20In%20Build%20an%20Excel%20Add-In%202%20%E2%80%93%20Enhanced%20Functionality%20I%20turned%20this%20routine%20into%20a%20mo" title="LinkedIn"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-3-auxiliary-modular-functions%2F&amp;title=Build%20an%20Excel%20Add-In%203%20-%20Auxiliary%20Modular%20Functions&amp;notes=In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20coded%20a%20procedure%20in%20VBA%20to%20create%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pivot%20table.%20In%20Build%20an%20Excel%20Add-In%202%20%E2%80%93%20Enhanced%20Functionality%20I%20turned%20this%20routine%20into%20a%20mo" title="del.icio.us"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-3-auxiliary-modular-functions%2F" title="Technorati"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-3-auxiliary-modular-functions%2F&amp;title=Build%20an%20Excel%20Add-In%203%20-%20Auxiliary%20Modular%20Functions" title="StumbleUpon"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-3-auxiliary-modular-functions%2F&amp;title=Build%20an%20Excel%20Add-In%203%20-%20Auxiliary%20Modular%20Functions&amp;annotation=In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20coded%20a%20procedure%20in%20VBA%20to%20create%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pivot%20table.%20In%20Build%20an%20Excel%20Add-In%202%20%E2%80%93%20Enhanced%20Functionality%20I%20turned%20this%20routine%20into%20a%20mo" title="Google Bookmarks"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-3-auxiliary-modular-functions%2F&amp;title=Build%20an%20Excel%20Add-In%203%20-%20Auxiliary%20Modular%20Functions" title="Reddit"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-3-auxiliary-modular-functions%2F&amp;t=Build%20an%20Excel%20Add-In%203%20-%20Auxiliary%20Modular%20Functions" title="MySpace"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Build%20an%20Excel%20Add-In%203%20-%20Auxiliary%20Modular%20Functions&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-3-auxiliary-modular-functions%2F" title="Slashdot"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-3-auxiliary-modular-functions%2F&amp;submitHeadline=Build%20an%20Excel%20Add-In%203%20-%20Auxiliary%20Modular%20Functions&amp;submitSummary=In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20coded%20a%20procedure%20in%20VBA%20to%20create%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pivot%20table.%20In%20Build%20an%20Excel%20Add-In%202%20%E2%80%93%20Enhanced%20Functionality%20I%20turned%20this%20routine%20into%20a%20mo&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-3-auxiliary-modular-functions%2F&amp;t=Build%20an%20Excel%20Add-In%203%20-%20Auxiliary%20Modular%20Functions&amp;s=In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20coded%20a%20procedure%20in%20VBA%20to%20create%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pivot%20table.%20In%20Build%20an%20Excel%20Add-In%202%20%E2%80%93%20Enhanced%20Functionality%20I%20turned%20this%20routine%20into%20a%20mo" title="Tumblr"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://peltiertech.com/WordPress/build-an-excel-add-in-3-auxiliary-modular-functions/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Build an Excel Add-In 2 &#8211; Enhanced Functionality</title>
		<link>http://peltiertech.com/WordPress/build-an-excel-add-in-2-enhanced-functionality/</link>
		<comments>http://peltiertech.com/WordPress/build-an-excel-add-in-2-enhanced-functionality/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 08:00:48 +0000</pubDate>
		<dc:creator>Jon Peltier</dc:creator>
				<category><![CDATA[VBA]]></category>
		<category><![CDATA[Add-ins]]></category>

		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=2753</guid>
		<description><![CDATA[In Build an Excel Add-In 1 – Basic Routine I coded a procedure in VBA to create a regular chart from an arbitrary rectangular range, including from a pivot table. In this post I will begin the process of turning this routine into an Excel add-in.
The VBA procedure in Build an Excel Add-In 1 – [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://peltiertech.com/WordPress/build-an-excel-add-in-1-basic-routine/"title="Build an Excel Add-In 1 – Basic Routine" >Build an Excel Add-In 1 – Basic Routine</a> I coded a procedure in VBA to create a regular chart from an arbitrary rectangular range, including from a pivot table. In this post I will begin the process of turning this routine into an Excel add-in.</p>
<p>The VBA procedure in <a href="../build-an-excel-add-in-1-basic-routine/" rel="nofollow" title="Build an Excel Add-In 1 – Basic Routine" >Build an Excel Add-In 1 – Basic Routine</a> is a subroutine which creates a chart using a number of built-in (hard-coded) options. In this post I will show how to make this subroutine into a modular function, which allows a calling procedure to pass these options into the procedure. This adds the flexibility that allows the function to create a variety of charts based on different options. In a future installment of this series I will build a dialog (a VBA UserForm) which allows a user to select these options.</p>
<h2><span id="more-2753"></span>Modular Function</h2>
<p>The first step in the transformation is to turn the subroutine in the previous step:</p>
<pre class="vbasmall"><code>Sub PT_Plot() </code></pre>
<p>into a function with parameters for the various options:</p>
<pre><code>Function PT_Plotter_Chart(DataRange As Range, DataOrientation As XlRowCol, _
    HeaderRows As Long, HeaderColumns As Long, ChartType As XlChartType, _
    Optional PositionRange As Range) As Chart</code></pre>
<p>The parameters passed into this function are:</p>
<pre class="vbasmall"><code>DataRange: a Range object containing the chart's source data
DataOrientation: whether series are specified by xlColumns or xlRows
HeaderRows: number of header rows in the data range (series names or category values)
HeaderColumns: number of header columns in the data range (series names or category values)
ChartType: type of chart to create (XY, Line, Area, Column, Bar)
PositionRange (optional): range of cells that chart object will cover </code></pre>
<p>The result of the function is a reference to the chart created in the function.</p>
<p>The calling procedure has defined the values of these parameters, and our function has to adjust its execution to account for these values.</p>
<h2>Chart Source Data Range</h2>
<p>In the original sub, if the selection is not a range, execution exits the procedure. Otherwise the selected range becomes the source data range:</p>
<pre class="vbasmall"><code>  If TypeName(Selection) &lt;&gt; "Range" Then
    MsgBox "Select a range and try again.", vbOKOnly, "No Range Selected"
    GoTo ExitProcedure
  End If
  Set rData = Selection</code></pre>
<p>In the new function, <tt class="tt">DataRange As Range</tt> is passed into the function.</p>
<h2>Header Rows and Columns, and Data Orientation</h2>
<p>The original sub assumes that there is one header row and one header column. The range containing the series values is offset one row down and one column right of the source data range, and reduced in size by one row and one column. In addition, it assumes that series are defined by columns, so the series names are defined as the top row, the category values as the left column, and the number of series as the number of columns in the series values range.</p>
<pre class="vbasmall"><code>  With rData
    Set rValues = .Offset(1, 1).Resize(.Rows.Count - 1, .Columns.Count - 1)
    nSrs = .Columns.Count - 1
    Set rNames = .Offset(, 1).Resize(1, nSrs)
    Set rCats = .Offset(1).Resize(.Rows.Count - 1, 1)
  End With</code></pre>
<p>The new function adjusts the position and size of the range containing the series values by the number of header rows and columns it is passed. The data orientation helps to define the number of series, the series names, and the category values.</p>
<pre class="vbasmall"><code>  With DataRange
    Set rValues = .Offset(HeaderRows, HeaderColumns) _
        .Resize(.Rows.Count - HeaderRows, .Columns.Count - HeaderColumns)
    Select Case DataOrientation
      Case xlColumns
        nSrs = .Columns.Count - HeaderColumns
        Set rNames = .Offset(, HeaderColumns).Resize(HeaderRows, nSrs)
        Set rCats = .Offset(HeaderRows) _
            .Resize(.Rows.Count - HeaderRows, HeaderColumns)
      Case xlRows
        nSrs = .Rows.Count - HeaderRows
        Set rNames = .Offset(HeaderRows).Resize(nSrs, HeaderColumns)
        Set rCats = .Offset(, HeaderColumns) _
            .Resize(HeaderRows, .Columns.Count - HeaderColumns)
    End Select
  End With </code></pre>
<p>Series are added to the chart as columns or as rows, based on the data orientation:</p>
<pre class="vbasmall"><code>  For iSrs = 1 To nSrs
    Set Srs = cht.SeriesCollection.NewSeries
    With Srs
      Select Case DataOrientation
        Case xlColumns
          .Values = rValues.Columns(iSrs)
          .XValues = rCats
          .Name = "=" &amp; rNames.Columns(iSrs).Address(ReferenceStyle:=xlR1C1, External:=True)
        Case xlRows
          .Values = rValues.Rows(iSrs)
          .XValues = rCats
          .Name = "=" &amp; rNames.Rows(iSrs).Address(ReferenceStyle:=xlR1C1, External:=True)
      End Select
    End With
  Next </code></pre>
<h2>Chart Type</h2>
<p>The original sub does not specify a chart type, so it creates a chart of the default type. If the user has not specified their own default, then the Excel default chart type, 2D clustered column, is used.</p>
<p>The new function applies the specified chart type to the finished chart:</p>
<pre class="vbasmall"><code>  cht.ChartType = ChartType </code></pre>
<h2>Chart Position</h2>
<p>The original sub mimics the Excel 2003 default chart object position, which is half the size of the active window, centered within the active window.</p>
<pre class="vbasmall"><code>  Set rScroll = ActiveSheet.Cells(ActiveWindow.ScrollRow, ActiveWindow.ScrollColumn)
  With ActiveWindow
    dWidth = .UsableWidth / 2
    dHeight = .UsableHeight / 2
    dLeft = rScroll.Left + dWidth / 2
    dTop = rScroll.Top + dHeight / 2
  End With</code></pre>
<p>If it is passed a range defining the chart position, the new function covers this range with the chart object.</p>
<pre class="vbasmall"><code>    With PositionRange
      dLeft = .Left
      dTop = .Top
      dWidth = .Width
      dHeight = .Height
    End With</code></pre>
<p>Otherwise, the function mimics the Excel 2003 default chart object position, using the largest pane instead of the entire active window. If the chart will be smaller than a minimum defined size, this defined minimum will be used rather than half the size of the largest pane.</p>
<pre class="vbasmall"><code>    With ActiveWindow
      dWidth = .UsableWidth / 2
      dHeight = .UsableHeight / 2
      If .SplitColumn &gt; 0 Then
        If ActiveSheet.Range("A1").Resize(, .SplitColumn).Width &gt; dWidth Then
          dWidth = ActiveSheet.Range("A1").Resize(, .SplitColumn).Width / 2
          If dWidth &lt; 200 Then dWidth = 200
          dLeft = ActiveSheet.Columns(.Panes(1).ScrollColumn).Left + dWidth / 2
        Else
          dWidth = dWidth - ActiveSheet.Range("A1").Resize(, .SplitColumn).Width / 2
          If dWidth &lt; 200 Then dWidth = 200
          dLeft = ActiveSheet.Columns(.Panes(.Panes.Count).ScrollColumn).Left + dWidth / 2
        End If
      Else
        If dWidth &lt; 200 Then dWidth = 200
        dLeft = ActiveSheet.Columns(.Panes(1).ScrollColumn).Left + dWidth / 2
      End If
      If dLeft &lt; 40 Then dLeft = 40
      If .SplitRow &gt; 0 Then
        If ActiveSheet.Range("A1").Resize(.SplitRow).Height &gt; dHeight Then
          dHeight = ActiveSheet.Range("A1").Resize(.SplitRow).Height / 2
          If dHeight &lt; 125 Then dHeight = 125
          dTop = ActiveSheet.Rows(.Panes(1).ScrollRow).Top + dHeight / 2
        Else
          dHeight = dHeight - ActiveSheet.Range("A1").Resize(.SplitRow).Height / 2
          If dHeight &lt; 125 Then dHeight = 125
          dTop = ActiveSheet.Rows(.Panes(.Panes.Count).ScrollRow).Top + dHeight / 2
        End If
      Else
        If dHeight &lt; 125 Then dHeight = 125
        dTop = ActiveSheet.Rows(.Panes(.Panes.Count).ScrollRow).Top + dHeight / 2
      End If
    If dTop &lt; 25 Then dTop = 25
    End With</code></pre>
<p>This set of calculations based on the splitting of the window into multiple panes is too complicated for this post, but it may be covered in a future post.</p>
<h2>Returned Value</h2>
<p>The function returns the chart that is created in the function:</p>
<pre class="vbasmall"><code>  Set PT_Plotter_Chart = cht</code></pre>
<h2>Entire Code of New Function</h2>
<p>The following is the listing of the updated procedure:</p>
<pre class="vbasmall"><code>Function PT_Plotter_Chart(DataRange As Range, DataOrientation As XlRowCol, _
    HeaderRows As Long, HeaderColumns As Long, ChartType As XlChartType, _
    Optional PositionRange As Range) As Chart

  <span style="color: #339966;">' CREATE AND POPULATE A CHART
  ' ' Start with defined data range
  ' ' Put chart in specified (or default) position
  ' ' Use specified chart type
  ' ' Plot by row or column as specified
  ' ' Use specified rows/columns for category values
  ' ' Use specified columns/rows for series names
  ' ' Use position range (if specified) for position of chart object
  ' ' Otherwise center chart object in largest pane of active window
</span>
  Dim ChtOb As ChartObject
  Dim cht As Chart
  Dim wsPosition As Worksheet
  Dim dLeft As Double, dTop As Double, dWidth As Double, dHeight As Double
  Dim rActive As Range
  Dim rScroll As Range
  Dim rCats As Range
  Dim rNames As Range
  Dim rValues As Range
  Dim iSrs As Long, nSrs As Long
  Dim Srs As Series
  Dim bScreenUpdating As Boolean

  bScreenUpdating = Application.ScreenUpdating
  Application.ScreenUpdating = False

  If TypeName(Selection) = "Range" Then
    Set rActive = ActiveCell
    Set rScroll = ActiveSheet.Cells(ActiveWindow.ScrollRow, ActiveWindow.ScrollColumn)
  End If
  If PositionRange Is Nothing Then
    <span style="color: #339966;">' Position unspecified
    ' Define using 2003 configuration
    ' Put into largest pane (whole window if unsplit)
    ' Half the pane's width and height, centered in pane</span>
    With ActiveWindow
      dWidth = .UsableWidth / 2
      dHeight = .UsableHeight / 2

      If .SplitColumn &gt; 0 Then
        If ActiveSheet.Range("A1").Resize(, .SplitColumn).Width &gt; dWidth Then
          dWidth = ActiveSheet.Range("A1").Resize(, .SplitColumn).Width / 2
          If dWidth &lt; 200 Then dWidth = 200
          dLeft = ActiveSheet.Columns(.Panes(1).ScrollColumn).Left + dWidth / 2
        Else
          dWidth = dWidth - ActiveSheet.Range("A1").Resize(, .SplitColumn).Width / 2
          If dWidth &lt; 200 Then dWidth = 200
          dLeft = ActiveSheet.Columns(.Panes(.Panes.Count).ScrollColumn).Left + dWidth / 2
        End If
      Else
        If dWidth &lt; 200 Then dWidth = 200
        dLeft = ActiveSheet.Columns(.Panes(1).ScrollColumn).Left + dWidth / 2
      End If
      If dLeft &lt; 40 Then dLeft = 40

      If .SplitRow &gt; 0 Then
        If ActiveSheet.Range("A1").Resize(.SplitRow).Height &gt; dHeight Then
          dHeight = ActiveSheet.Range("A1").Resize(.SplitRow).Height / 2
          If dHeight &lt; 125 Then dHeight = 125
          dTop = ActiveSheet.Rows(.Panes(1).ScrollRow).Top + dHeight / 2
        Else
          dHeight = dHeight - ActiveSheet.Range("A1").Resize(.SplitRow).Height / 2
          If dHeight &lt; 125 Then dHeight = 125
          dTop = ActiveSheet.Rows(.Panes(.Panes.Count).ScrollRow).Top + dHeight / 2
        End If
      Else
        If dHeight &lt; 125 Then dHeight = 125
        dTop = ActiveSheet.Rows(.Panes(.Panes.Count).ScrollRow).Top + dHeight / 2
      End If
      If dTop &lt; 25 Then dTop = 25

    End With
    Set wsPosition = ActiveSheet
  Else
    <span style="color: #339966;">' Position specified</span>
    With PositionRange
      dLeft = .Left
      dTop = .Top
      dWidth = .Width
      dHeight = .Height
      Set wsPosition = .Parent
    End With
  End If

  With DataRange
    Set rValues = .Offset(HeaderRows, HeaderColumns) _
        .Resize(.Rows.Count - HeaderRows, .Columns.Count - HeaderColumns)
    Select Case DataOrientation
      Case xlColumns
        nSrs = .Columns.Count - HeaderColumns
        Set rNames = .Offset(, HeaderColumns).Resize(HeaderRows, nSrs)
        Set rCats = .Offset(HeaderRows) _
            .Resize(.Rows.Count - HeaderRows, HeaderColumns)
      Case xlRows
        nSrs = .Rows.Count - HeaderRows
        Set rNames = .Offset(HeaderRows).Resize(nSrs, HeaderColumns)
        Set rCats = .Offset(, HeaderColumns) _
            .Resize(HeaderRows, .Columns.Count - HeaderColumns)
    End Select
  End With

  <span style="color: #339966;">' NEED ACTIVE CELL NOT IN PIVOT TABLE WHEN CREATING CHART</span>
  If Not rActive Is Nothing Then
    ActiveSheet.Columns(1).Cells(ActiveSheet.Rows.Count).Select
  End If

  Set cht = wsPosition.ChartObjects.Add(dLeft, dTop, dWidth, dHeight).Chart
  <span style="color: #339966;">' probably blank, but remove all series just in case</span>
  For iSrs = cht.SeriesCollection.Count To 1 Step -1
    cht.SeriesCollection.Count(iSrs).Delete
  Next

  <span style="color: #339966;">' add series from data range</span>
  For iSrs = 1 To nSrs
    Set Srs = cht.SeriesCollection.NewSeries
    With Srs
      Select Case DataOrientation
        Case xlColumns
          .Values = rValues.Columns(iSrs)
          .XValues = rCats
          .Name = "=" &amp; rNames.Columns(iSrs).Address(ReferenceStyle:=xlR1C1, External:=True)
        Case xlRows
          .Values = rValues.Rows(iSrs)
          .XValues = rCats
          .Name = "=" &amp; rNames.Rows(iSrs).Address(ReferenceStyle:=xlR1C1, External:=True)
      End Select
    End With
  Next
  cht.ChartType = ChartType

  Set PT_Plotter_Chart = cht

  <span style="color: #339966;">' restore original window configuration</span>
  ActiveWindow.ScrollRow = rScroll.Row
  ActiveWindow.ScrollColumn = rScroll.Column
  If Not rActive Is Nothing Then
    DataRange.Select
    rActive.Activate
  End If

  Application.ScreenUpdating = bScreenUpdating

End Function</code></pre>
<h2>Contents: How to Build an Excel Add-In</h2>
<ul style="margin-left: 24pt;">
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-1-basic-routine/"title="Build an Excel Add-In 1 – Basic Routine" >Build an Excel Add-In 1 – Basic Routine</a></li>
<li><strong>Build an Excel Add-In 2 – Enhanced Functionality</strong></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-3-auxiliary-modular-functions/"title="Build an Excel Add-In 3 - Auxiliary Modular Functions" >Build an Excel Add-In 3 &#8211; Auxiliary Modular Functions</a></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-4-create-the-dialog/"title="Build an Excel Add-In 4 – Create the Dialog" >Build an Excel Add-In 4 – Create the Dialog</a></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-5-tie-it-all-together/"title="Build an Excel Add-In 5 – Tie the Code Together" >Build an Excel Add-In 5 – Tie the Code Together</a></li>
<li>Build an Excel Add-In 6 – Interface for 2003</li>
<li>Build an Excel Add-In 7 – Interface for 2007</li>
<li>Build an Excel Add-In 8 – Last Steps</li>
<li>Build an Excel Add-In 9 – Deployment</li>
</ul>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 1392px; width: 1px; height: 1px;">.Name = &#8220;=&#8221; &amp; rNames.Columns(iSrs).Address(ReferenceStyle:=xlR1C1, External:=True)</div>
<p>Peltier Technical Services, Inc., Copyright © 2010.<br /> <br /><span style="font: 80% Verdana,Tahoma,Arial,sans-serif;">Licensed under a <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/" rel="nofollow" rel="license" >Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.<br /> <br />
<a href="http://www.exceluser.com/cmd.asp?Clk=1374689" rel="nofollow" ><IMG SRC="http://www.exceluser.com/images/info/pub/info_dash_c02.gif" ALT="Learn how to create Excel dashboards." WIDTH="468" HEIGHT="60" border=0></a><br />
<br /><img src="http://www.exceluser.com/cmd.asp?Imp=1374689" width="0" height="0" border="0"></p>



Bookmark and share this entry:


	<a rel="nofollow"  href="http://twitter.com/home?status=Build%20an%20Excel%20Add-In%202%20-%20Enhanced%20Functionality%20-%20http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-2-enhanced-functionality%2F" title="Twitter"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-2-enhanced-functionality%2F&amp;title=Build%20an%20Excel%20Add-In%202%20-%20Enhanced%20Functionality&amp;bodytext=In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20coded%20a%20procedure%20in%20VBA%20to%20create%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pivot%20table.%20In%20this%20post%20I%20will%20begin%20the%20process%20of%20turning%20this%20routine%20into%20an%20Excel%20add-in.%0D%0A" title="Digg"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-2-enhanced-functionality%2F&amp;t=Build%20an%20Excel%20Add-In%202%20-%20Enhanced%20Functionality" title="Facebook"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-2-enhanced-functionality%2F&amp;title=Build%20an%20Excel%20Add-In%202%20-%20Enhanced%20Functionality&amp;source=Peltier+Tech+Blog+Peltier+Tech+Excel+Charts+and+Programming+Blog&amp;summary=In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20coded%20a%20procedure%20in%20VBA%20to%20create%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pivot%20table.%20In%20this%20post%20I%20will%20begin%20the%20process%20of%20turning%20this%20routine%20into%20an%20Excel%20add-in.%0D%0A" title="LinkedIn"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-2-enhanced-functionality%2F&amp;title=Build%20an%20Excel%20Add-In%202%20-%20Enhanced%20Functionality&amp;notes=In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20coded%20a%20procedure%20in%20VBA%20to%20create%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pivot%20table.%20In%20this%20post%20I%20will%20begin%20the%20process%20of%20turning%20this%20routine%20into%20an%20Excel%20add-in.%0D%0A" title="del.icio.us"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-2-enhanced-functionality%2F" title="Technorati"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-2-enhanced-functionality%2F&amp;title=Build%20an%20Excel%20Add-In%202%20-%20Enhanced%20Functionality" title="StumbleUpon"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-2-enhanced-functionality%2F&amp;title=Build%20an%20Excel%20Add-In%202%20-%20Enhanced%20Functionality&amp;annotation=In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20coded%20a%20procedure%20in%20VBA%20to%20create%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pivot%20table.%20In%20this%20post%20I%20will%20begin%20the%20process%20of%20turning%20this%20routine%20into%20an%20Excel%20add-in.%0D%0A" title="Google Bookmarks"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-2-enhanced-functionality%2F&amp;title=Build%20an%20Excel%20Add-In%202%20-%20Enhanced%20Functionality" title="Reddit"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-2-enhanced-functionality%2F&amp;t=Build%20an%20Excel%20Add-In%202%20-%20Enhanced%20Functionality" title="MySpace"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Build%20an%20Excel%20Add-In%202%20-%20Enhanced%20Functionality&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-2-enhanced-functionality%2F" title="Slashdot"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-2-enhanced-functionality%2F&amp;submitHeadline=Build%20an%20Excel%20Add-In%202%20-%20Enhanced%20Functionality&amp;submitSummary=In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20coded%20a%20procedure%20in%20VBA%20to%20create%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pivot%20table.%20In%20this%20post%20I%20will%20begin%20the%20process%20of%20turning%20this%20routine%20into%20an%20Excel%20add-in.%0D%0A&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-2-enhanced-functionality%2F&amp;t=Build%20an%20Excel%20Add-In%202%20-%20Enhanced%20Functionality&amp;s=In%20Build%20an%20Excel%20Add-In%201%20%E2%80%93%20Basic%20Routine%20I%20coded%20a%20procedure%20in%20VBA%20to%20create%20a%20regular%20chart%20from%20an%20arbitrary%20rectangular%20range%2C%20including%20from%20a%20pivot%20table.%20In%20this%20post%20I%20will%20begin%20the%20process%20of%20turning%20this%20routine%20into%20an%20Excel%20add-in.%0D%0A" title="Tumblr"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://peltiertech.com/WordPress/build-an-excel-add-in-2-enhanced-functionality/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Build an Excel Add-In 1 &#8211; Basic Routine</title>
		<link>http://peltiertech.com/WordPress/build-an-excel-add-in-1-basic-routine/</link>
		<comments>http://peltiertech.com/WordPress/build-an-excel-add-in-1-basic-routine/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 08:00:48 +0000</pubDate>
		<dc:creator>Jon Peltier</dc:creator>
				<category><![CDATA[VBA]]></category>
		<category><![CDATA[Add-ins]]></category>

		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=2747</guid>
		<description><![CDATA[Sometimes you have data that&#8217;s been analyzed in a pivot table, and you want to graph it, but a pivot chart doesn&#8217;t do what you want. In Regular Charts from Pivot Tables I showed how to create a regular chart from a pivot table. I described a manual process, which works fine, but becomes tedious.
In [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you have data that&#8217;s been analyzed in a pivot table, and you want to graph it, but a pivot chart doesn&#8217;t do what you want. In <a href="http://peltiertech.com/WordPress/regular-charts-from-pivot-tables/"title="Regular Charts from Pivot Tables | PTS Blog" >Regular Charts from Pivot Tables</a> I showed how to create a regular chart from a pivot table. I described a manual process, which works fine, but becomes tedious.</p>
<p>In a recent project I had to make a number of regular charts from pivot tables, and I finally got tired of the long, slow, tedious manual process. I put together some VBA code and built myself an add-in so I would always have this functionality on hand. The add-in is also handy as a Chart Wizard replacement for Excel 2007, which lost the Wizard in the User Interface Wars.</p>
<p>I thought it would be nice to post this add-in on my blog, for all of you faithful readers. I frequently share such routines, and judging from comments and emails, they are pretty popular. Then I remembered that whole teach-a-man-to-fish thing, and decided it would be a great series of posts if I described the whole process of developing an Excel add-in.</p>
<p><span id="more-2747"></span>Here is the table of contents for this series.</p>
<ul style="margin-left: 24pt;">
<li><strong>Build an Excel Add-In 1 – Basic Routine</strong></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-2-enhanced-functionality/"title="Build an Excel Add-In 2 - Enhanced Functionality" >Build an Excel Add-In 2 – Enhanced Functionality</a></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-3-auxiliary-modular-functions/"title="Build an Excel Add-In 3 - Auxiliary Modular Functions" >Build an Excel Add-In 3 – Auxiliary Modular Functions</a></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-4-create-the-dialog/"title="Build an Excel Add-In 4 – Create the Dialog" >Build an Excel Add-In 4 – Create the Dialog</a></li>
<li><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-5-tie-it-all-together/"title="Build an Excel Add-In 5 – Tie the Code Together" >Build an Excel Add-In 5 – Tie the Code Together</a></li>
<li>Build an Excel Add-In 6 – Interface for 2003</li>
<li>Build an Excel Add-In 7 – Interface for 2007</li>
<li>Build an Excel Add-In 8 – Last Steps</li>
<li>Build an Excel Add-In 9 – Deployment</li>
</ul>
<p>And now, on to the first topic of the series:</p>
<h2>Build an Excel Add-In 1 &#8211; Basic Routine</h2>
<p>The steps in the manual procedure involve selecting a cell which is blank and not part of the pivot table, inserting a blank chart, and adding one series per column (or row) of the pivot table, using the first column as categories and the first row as series names.</p>
<p>The VBA procedure will use the selected range as the chart data source. It will assume that the series are in columns, that categories are in the first column, and that series names are in the first row. It will create the default chart type (clustered column if you&#8217;ve never reassigned your default), positioned according to the defaults in &#8220;Classic&#8221; Excel, that is, Excel 2003 and earlier. This default positioning creates a chart roughly half the <span style="text-decoration: line-through;">size</span> dimensions of the active window, roughly centered in the visible region of the active window.</p>
<p>Here is the whole VBA routine:</p>
<pre class="vbasmall"><code>Sub PT_Plot()

  <span style="color: #008000;">' CREATE AND POPULATE A CHART
  ' ' Start with selected data range
  ' ' Add chart object
  ' ' Use default chart type
  ' ' Plot by column
  ' ' First column for category values
  ' ' First row for series names</span>

  Dim ChtOb As ChartObject
  Dim cht As Chart
  Dim dLeft As Double, dTop As Double, dWidth As Double, dHeight As Double
  Dim rScroll As Range
  Dim rData As Range
  Dim rCats As Range
  Dim rNames As Range
  Dim rValues As Range
  Dim iSrs As Long, nSrs As Long
  Dim Srs As Series
  Dim shp As Shape

  Application.ScreenUpdating = False

  If TypeName(Selection) &lt;&gt; "Range" Then
    MsgBox "Select a range and try again.", vbOKOnly, "No Range Selected"
    GoTo ExitProcedure
  End If

  Set rData = Selection

  <span style="color: #008000;">' determine chart object size:
  ' ' half of window height and width, centered in window</span>
  Set rScroll = ActiveSheet.Cells _
      (ActiveWindow.ScrollRow, ActiveWindow.ScrollColumn)
  With ActiveWindow
    dWidth = .UsableWidth / 2
    dHeight = .UsableHeight / 2
    dLeft = rScroll.Left + dWidth / 2
    dTop = rScroll.Top + dHeight / 2
  End With

  With rData
    Set rValues = .Offset(1, 1).Resize(.Rows.Count - 1, .Columns.Count - 1)
    nSrs = .Columns.Count - 1
    Set rNames = .Offset(, 1).Resize(1, nSrs)
    Set rCats = .Offset(1).Resize(.Rows.Count - 1, 1)
  End With

  <span style="color: #008000;">' NEED ACTIVE CELL NOT IN PIVOT TABLE WHEN CREATING CHART</span>
  ActiveSheet.Columns(1).Cells(ActiveSheet.Rows.Count).Select

  Set cht = ActiveSheet.ChartObjects.Add(dLeft, dTop, dWidth, dHeight).Chart
  <span style="color: #008000;">' probably blank, but remove all series just in case</span>
  For iSrs = cht.SeriesCollection.Count To 1 Step -1
    cht.SeriesCollection.Count(iSrs).Delete
  Next

  <span style="color: #008000;">' add series from data range</span>
  For iSrs = 1 To nSrs
    Set Srs = cht.SeriesCollection.NewSeries
    With Srs
      .Values = rValues.Columns(iSrs)
      .XValues = rCats
      .Name = "=" &amp; rNames.Columns(iSrs).Address(ReferenceStyle:=xlR1C1, External:=True)
    End With
  Next

  <span style="color: #008000;">' restore original window configuration</span>
  ActiveWindow.ScrollRow = rScroll.Row
  ActiveWindow.ScrollColumn = rScroll.Column
  rData.Select 

ExitProcedure:

  Application.ScreenUpdating = True 

End Sub </code></pre>
<p>The way to use this program is to select your data, including a header row and header column, and run the procedure. The data below comes from a very simple pivot table.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlotSourceData.png" alt="pivot table chart source data" /></p>
<p>The easiest way to run the program is to press Alt-F8, select the PT_Plot macro from the list of available macros, and press Enter.<br class="spacer_" /></p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlotMacroDialog.png" alt="Excel macros dialog" /></p>
<p>You can also see PT_Plotter_Dialog in the list. This is the routine which will eventually be called from the menu or ribbon in the add-in. You&#8217;ll have to be patient as it will be refined over the next few installments.</p>
<p>The output of the program is a chart object half the size of the active window, centered in the window. It is the default clustered column type, with default formatting.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://peltiertech.com/images/2010-01/PTPlotSimple.png" alt="program output: regular chart from pivot table" /></p>
<h2>Coming Attractions</h2>
<p>In <a href="../build-an-excel-add-in-2-enhanced-functionality/" rel="nofollow" title="Build an Excel Add-In 2 - Enhanced Functionality" >Build an Excel Add-In 2 – Enhanced Functionality</a>, this sub will be converted to a function. Various arguments, such as chart source data range, data series orientation, number of header row(s) and column(s), chart type, and optionally the position of chart, will be passed into the function. The function will return an object representing the chart it has constructed.</p>
<p><a href="../build-an-excel-add-in-3-auxiliary-modular-functions/" rel="nofollow" title="Build an Excel Add-In 3 - Auxiliary Modular Functions" >Build an Excel Add-In 3 – Auxiliary Modular Functions</a> will demonstrate how to incorporate additional functionality in the form of additional functions, which can be shared among any of your procedures. The particular function will be a routine that takes the chart as an argument, applies some &#8220;nice&#8221; formatting, and returns the cleaned up chart.</p>
<p>We will add a user interface in <a href="http://peltiertech.com/WordPress/build-an-excel-add-in-4-create-the-dialog/"title="Build an Excel Add-In 4 – Create the Dialog" >Build an Excel Add-In 4 – Create the Dialog</a> that will allow the user to easily select the arguments that are passed into the function we developed in installment 2. The PT_Plotter_Dialog will incorporate the use of this dialog, then call the function to create the chart. At this point, the features of the add-in are complete.</p>
<p><a href="http://peltiertech.com/WordPress/build-an-excel-add-in-5-tie-it-all-together/"title="Build an Excel Add-In 5 – Tie the Code Together" >Build an Excel Add-In 5 – Tie the Code Together</a> will merge the function that creates the chart, the auxiliary function that formats the chart, and the dialog and the code that interacts with the dialog.</p>
<p>The add-in still needs to make itself visible in the Excel application. This will be done using a custom menu and button in <strong>Build an Excel Add-In 6 – Interface for 2003</strong> and using a custom ribbon tab and button in <strong>Build an Excel Add-In 7 – Interface for 2007</strong>.</p>
<p><strong>Build an Excel Add-In 8 – Last Steps</strong> describes some final tasks to ensure your add-in will work properly on a wide range of version combinations of Windows and Excel. <strong>Build an Excel Add-In 9 – Deployment</strong> will talk about issues you may encounter while deploying your add-in to other users.</p>
<p>Peltier Technical Services, Inc., Copyright © 2010.<br /> <br /><span style="font: 80% Verdana,Tahoma,Arial,sans-serif;">Licensed under a <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/" rel="nofollow" rel="license" >Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.<br /> <br />
<a href="http://www.exceluser.com/cmd.asp?Clk=1374689" rel="nofollow" ><IMG SRC="http://www.exceluser.com/images/info/pub/info_dash_c02.gif" ALT="Learn how to create Excel dashboards." WIDTH="468" HEIGHT="60" border=0></a><br />
<br /><img src="http://www.exceluser.com/cmd.asp?Imp=1374689" width="0" height="0" border="0"></p>



Bookmark and share this entry:


	<a rel="nofollow"  href="http://twitter.com/home?status=Build%20an%20Excel%20Add-In%201%20-%20Basic%20Routine%20-%20http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-1-basic-routine%2F" title="Twitter"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-1-basic-routine%2F&amp;title=Build%20an%20Excel%20Add-In%201%20-%20Basic%20Routine&amp;bodytext=Sometimes%20you%20have%20data%20that%27s%20been%20analyzed%20in%20a%20pivot%20table%2C%20and%20you%20want%20to%20graph%20it%2C%20but%20a%20pivot%20chart%20doesn%27t%20do%20what%20you%20want.%20In%20Regular%20Charts%20from%20Pivot%20Tables%20I%20showed%20how%20to%20create%20a%20regular%20chart%20from%20a%20pivot%20table.%20I%20described%20a%20manual%20p" title="Digg"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-1-basic-routine%2F&amp;t=Build%20an%20Excel%20Add-In%201%20-%20Basic%20Routine" title="Facebook"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-1-basic-routine%2F&amp;title=Build%20an%20Excel%20Add-In%201%20-%20Basic%20Routine&amp;source=Peltier+Tech+Blog+Peltier+Tech+Excel+Charts+and+Programming+Blog&amp;summary=Sometimes%20you%20have%20data%20that%27s%20been%20analyzed%20in%20a%20pivot%20table%2C%20and%20you%20want%20to%20graph%20it%2C%20but%20a%20pivot%20chart%20doesn%27t%20do%20what%20you%20want.%20In%20Regular%20Charts%20from%20Pivot%20Tables%20I%20showed%20how%20to%20create%20a%20regular%20chart%20from%20a%20pivot%20table.%20I%20described%20a%20manual%20p" title="LinkedIn"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-1-basic-routine%2F&amp;title=Build%20an%20Excel%20Add-In%201%20-%20Basic%20Routine&amp;notes=Sometimes%20you%20have%20data%20that%27s%20been%20analyzed%20in%20a%20pivot%20table%2C%20and%20you%20want%20to%20graph%20it%2C%20but%20a%20pivot%20chart%20doesn%27t%20do%20what%20you%20want.%20In%20Regular%20Charts%20from%20Pivot%20Tables%20I%20showed%20how%20to%20create%20a%20regular%20chart%20from%20a%20pivot%20table.%20I%20described%20a%20manual%20p" title="del.icio.us"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-1-basic-routine%2F" title="Technorati"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-1-basic-routine%2F&amp;title=Build%20an%20Excel%20Add-In%201%20-%20Basic%20Routine" title="StumbleUpon"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-1-basic-routine%2F&amp;title=Build%20an%20Excel%20Add-In%201%20-%20Basic%20Routine&amp;annotation=Sometimes%20you%20have%20data%20that%27s%20been%20analyzed%20in%20a%20pivot%20table%2C%20and%20you%20want%20to%20graph%20it%2C%20but%20a%20pivot%20chart%20doesn%27t%20do%20what%20you%20want.%20In%20Regular%20Charts%20from%20Pivot%20Tables%20I%20showed%20how%20to%20create%20a%20regular%20chart%20from%20a%20pivot%20table.%20I%20described%20a%20manual%20p" title="Google Bookmarks"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-1-basic-routine%2F&amp;title=Build%20an%20Excel%20Add-In%201%20-%20Basic%20Routine" title="Reddit"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-1-basic-routine%2F&amp;t=Build%20an%20Excel%20Add-In%201%20-%20Basic%20Routine" title="MySpace"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Build%20an%20Excel%20Add-In%201%20-%20Basic%20Routine&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-1-basic-routine%2F" title="Slashdot"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-1-basic-routine%2F&amp;submitHeadline=Build%20an%20Excel%20Add-In%201%20-%20Basic%20Routine&amp;submitSummary=Sometimes%20you%20have%20data%20that%27s%20been%20analyzed%20in%20a%20pivot%20table%2C%20and%20you%20want%20to%20graph%20it%2C%20but%20a%20pivot%20chart%20doesn%27t%20do%20what%20you%20want.%20In%20Regular%20Charts%20from%20Pivot%20Tables%20I%20showed%20how%20to%20create%20a%20regular%20chart%20from%20a%20pivot%20table.%20I%20described%20a%20manual%20p&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Fbuild-an-excel-add-in-1-basic-routine%2F&amp;t=Build%20an%20Excel%20Add-In%201%20-%20Basic%20Routine&amp;s=Sometimes%20you%20have%20data%20that%27s%20been%20analyzed%20in%20a%20pivot%20table%2C%20and%20you%20want%20to%20graph%20it%2C%20but%20a%20pivot%20chart%20doesn%27t%20do%20what%20you%20want.%20In%20Regular%20Charts%20from%20Pivot%20Tables%20I%20showed%20how%20to%20create%20a%20regular%20chart%20from%20a%20pivot%20table.%20I%20described%20a%20manual%20p" title="Tumblr"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://peltiertech.com/WordPress/build-an-excel-add-in-1-basic-routine/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>List VBA Procedures by VBA Module and VB Procedure</title>
		<link>http://peltiertech.com/WordPress/list-vba-procedures-by-vba-module-and-vb-procedure/</link>
		<comments>http://peltiertech.com/WordPress/list-vba-procedures-by-vba-module-and-vb-procedure/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 06:00:50 +0000</pubDate>
		<dc:creator>Jon Peltier</dc:creator>
				<category><![CDATA[VBA]]></category>
		<category><![CDATA[VBIDE]]></category>

		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=2717</guid>
		<description><![CDATA[Mathias Brandewinder of Clear Lines Blog tweeted up Displaying a List of All VBA Procedures in an Excel 2007 Workbook from the Ribbon, an article by Microsoft&#8217;s Frank Rice on the MSDN web site, which showed a VBA procedure for listing all of the VBA procedures in a VB project. Interesting procedure, could be very [...]]]></description>
			<content:encoded><![CDATA[<p>Mathias Brandewinder of <a href="http://clear-lines.com/blog/" rel="nofollow" title="Clear Lines Blog | quantitative analysis, .NET applications, Excel, decision making, and a whole lot of other random things" >Clear Lines Blog</a> tweeted up <a href="http://msdn.microsoft.com/en-us/library/dd890502(office.11).aspx#" rel="nofollow" title="Displaying a List of All VBA Procedures in an Excel 2007 Workbook from the Ribbon (June 2009)" >Displaying a List of All VBA Procedures in an Excel 2007 Workbook from the Ribbon</a>, an article by Microsoft&#8217;s Frank Rice on the MSDN web site, which showed a VBA procedure for listing all of the VBA procedures in a VB project. Interesting procedure, could be very useful.</p>
<p>Not being able to leave anything alone, I made some changes to how the procedure worked. The original put its list of procedures into a dialog, and when the dialog was closed, the list evaporated. I changed the output so that the list is dumped into a new worksheet inserted just for this purpose.</p>
<p>I broadened the scope of the procedure, so that it lists all procedures in all VB projects, not just the active one. The first two rows of the output sheet contain the names of the parent workbook and of the project.</p>
<p>If the project is protected, you&#8217;ll get an error if you try to look inside, so my code bypasses the error and notes that the project is protected. My code also notes when there isn&#8217;t any code in a project.</p>
<p>I also didn&#8217;t find the original variable names useful, so I used some which were more descriptive, to me at least.</p>
<p><span id="more-2717"></span>Here&#8217;s my modified procedure, for what it&#8217;s worth.</p>
<pre class="vbasmall"><span style="color: #339966;">'' Based on:
'' Displaying a List of All VBA Procedures in an Excel 2007 Workbook
''     from the Ribbon (June 2009)
'' by Frank Rice, Microsoft Corporation
'' http://msdn.microsoft.com/en-us/library/dd890502(office.11).aspx#</span>

<span style="color: #339966;">'' set a reference to the Microsoft Visual Basic for Applications Extensibility 5.3 Library</span>

Sub GetProcedures()
  <span style="color: #339966;">' Declare variables to access the Excel workbook.</span>
  Dim app As Excel.Application
  Dim wb As Excel.Workbook
  Dim wsOutput As Excel.Worksheet
  Dim sOutput() As String
  Dim sFileName As String

  <span style="color: #339966;">' Declare variables to access the macros in the workbook.</span>
  Dim vbProj As VBIDE.VBProject
  Dim vbComp As VBIDE.VBComponent
  Dim vbMod As VBIDE.CodeModule

  <span style="color: #339966;">' Declare other miscellaneous variables.</span>
  Dim iRow As Long
  Dim iCol As Long
  Dim iLine As Integer
  Dim sProcName As String
  Dim pk As vbext_ProcKind

  Set app = Excel.Application

  <span style="color: #339966;">' create new workbook for output</span>
  Set wsOutput = app.Workbooks.Add.Worksheets(1)

  'For Each wb In app.Workbooks
  For Each vbProj In app.VBE.VBProjects

    <span style="color: #339966;">' Get the project details in the workbook.</span>
    On Error Resume Next
    sFileName = vbProj.Filename
    If Err.Number &lt;&gt; 0 Then sFileName = "file not saved"
    On Error GoTo 0

    <span style="color: #339966;">' initialize output array</span>
    ReDim sOutput(1 To 2)
    sOutput(1) = sFileName
    sOutput(2) = vbProj.Name
    iRow = 0

    <span style="color: #339966;">' check for protected project</span>
    On Error Resume Next
    Set vbComp = vbProj.VBComponents(1)
    On Error GoTo 0

    If Not vbComp Is Nothing Then
      <span style="color: #339966;">' Iterate through each component in the project.</span>
      For Each vbComp In vbProj.VBComponents

        <span style="color: #339966;">' Find the code module for the project.</span>
        Set vbMod = vbComp.CodeModule

        <span style="color: #339966;">' Scan through the code module, looking for procedures.</span>
        iLine = 1
        Do While iLine &lt; vbMod.CountOfLines
          sProcName = vbMod.ProcOfLine(iLine, pk)
          If sProcName &lt;&gt; "" Then
            iRow = iRow + 1
            ReDim Preserve sOutput(1 To 2 + iRow)
            sOutput(2 + iRow) = vbComp.Name &amp; ": " &amp; sProcName
            iLine = iLine + vbMod.ProcCountLines(sProcName, pk)
          Else
            <span style="color: #339966;">' This line has no procedure, so go to the next line.</span>
            iLine = iLine + 1
          End If
        Loop

        <span style="color: #339966;">' clean up</span>
        Set vbMod = Nothing
        Set vbComp = Nothing

      Next
    Else
      ReDim Preserve sOutput(1 To 3)
      sOutput(3) = "Project protected"
    End If

    If UBound(sOutput) = 2 Then
      ReDim Preserve sOutput(1 To 3)
      sOutput(3) = "No code in project"
    End If

    <span style="color: #339966;">' define output location and dump output</span>
    If Len(wsOutput.Range("A1").Value) = 0 Then
      iCol = 1
    Else
      iCol = wsOutput.Cells(1, wsOutput.Columns.Count).End(xlToLeft).Column + 1
    End If
    wsOutput.Cells(1, iCol).Resize(UBound(sOutput) + 1 - LBound(sOutput)).Value = _
        WorksheetFunction.Transpose(sOutput)

    <span style="color: #339966;">' clean up</span>
    Set vbProj = Nothing
  Next

  <span style="color: #339966;">' clean up
</span>  wsOutput.UsedRange.Columns.AutoFit
End Sub
 </pre>
<p><br class="spacer_" /></p>
<p>Peltier Technical Services, Inc., Copyright © 2010.<br /> <br /><span style="font: 80% Verdana,Tahoma,Arial,sans-serif;">Licensed under a <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/" rel="nofollow" rel="license" >Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.<br /> <br />
<a href="http://www.exceluser.com/cmd.asp?Clk=1374689" rel="nofollow" ><IMG SRC="http://www.exceluser.com/images/info/pub/info_dash_c02.gif" ALT="Learn how to create Excel dashboards." WIDTH="468" HEIGHT="60" border=0></a><br />
<br /><img src="http://www.exceluser.com/cmd.asp?Imp=1374689" width="0" height="0" border="0"></p>



Bookmark and share this entry:


	<a rel="nofollow"  href="http://twitter.com/home?status=List%20VBA%20Procedures%20by%20VBA%20Module%20and%20VB%20Procedure%20-%20http%3A%2F%2Fpeltiertech.com%2FWordPress%2Flist-vba-procedures-by-vba-module-and-vb-procedure%2F" title="Twitter"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Flist-vba-procedures-by-vba-module-and-vb-procedure%2F&amp;title=List%20VBA%20Procedures%20by%20VBA%20Module%20and%20VB%20Procedure&amp;bodytext=Mathias%20Brandewinder%20of%20Clear%20Lines%20Blog%20tweeted%20up%20Displaying%20a%20List%20of%20All%20VBA%20Procedures%20in%20an%20Excel%202007%20Workbook%20from%20the%20Ribbon%2C%20an%20article%20by%20Microsoft%27s%20Frank%20Rice%20on%20the%20MSDN%20web%20site%2C%20which%20showed%20a%20VBA%20procedure%20for%20listing%20all%20of%20the%20VBA%20" title="Digg"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Flist-vba-procedures-by-vba-module-and-vb-procedure%2F&amp;t=List%20VBA%20Procedures%20by%20VBA%20Module%20and%20VB%20Procedure" title="Facebook"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Flist-vba-procedures-by-vba-module-and-vb-procedure%2F&amp;title=List%20VBA%20Procedures%20by%20VBA%20Module%20and%20VB%20Procedure&amp;source=Peltier+Tech+Blog+Peltier+Tech+Excel+Charts+and+Programming+Blog&amp;summary=Mathias%20Brandewinder%20of%20Clear%20Lines%20Blog%20tweeted%20up%20Displaying%20a%20List%20of%20All%20VBA%20Procedures%20in%20an%20Excel%202007%20Workbook%20from%20the%20Ribbon%2C%20an%20article%20by%20Microsoft%27s%20Frank%20Rice%20on%20the%20MSDN%20web%20site%2C%20which%20showed%20a%20VBA%20procedure%20for%20listing%20all%20of%20the%20VBA%20" title="LinkedIn"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Flist-vba-procedures-by-vba-module-and-vb-procedure%2F&amp;title=List%20VBA%20Procedures%20by%20VBA%20Module%20and%20VB%20Procedure&amp;notes=Mathias%20Brandewinder%20of%20Clear%20Lines%20Blog%20tweeted%20up%20Displaying%20a%20List%20of%20All%20VBA%20Procedures%20in%20an%20Excel%202007%20Workbook%20from%20the%20Ribbon%2C%20an%20article%20by%20Microsoft%27s%20Frank%20Rice%20on%20the%20MSDN%20web%20site%2C%20which%20showed%20a%20VBA%20procedure%20for%20listing%20all%20of%20the%20VBA%20" title="del.icio.us"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Flist-vba-procedures-by-vba-module-and-vb-procedure%2F" title="Technorati"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Flist-vba-procedures-by-vba-module-and-vb-procedure%2F&amp;title=List%20VBA%20Procedures%20by%20VBA%20Module%20and%20VB%20Procedure" title="StumbleUpon"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Flist-vba-procedures-by-vba-module-and-vb-procedure%2F&amp;title=List%20VBA%20Procedures%20by%20VBA%20Module%20and%20VB%20Procedure&amp;annotation=Mathias%20Brandewinder%20of%20Clear%20Lines%20Blog%20tweeted%20up%20Displaying%20a%20List%20of%20All%20VBA%20Procedures%20in%20an%20Excel%202007%20Workbook%20from%20the%20Ribbon%2C%20an%20article%20by%20Microsoft%27s%20Frank%20Rice%20on%20the%20MSDN%20web%20site%2C%20which%20showed%20a%20VBA%20procedure%20for%20listing%20all%20of%20the%20VBA%20" title="Google Bookmarks"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Flist-vba-procedures-by-vba-module-and-vb-procedure%2F&amp;title=List%20VBA%20Procedures%20by%20VBA%20Module%20and%20VB%20Procedure" title="Reddit"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Flist-vba-procedures-by-vba-module-and-vb-procedure%2F&amp;t=List%20VBA%20Procedures%20by%20VBA%20Module%20and%20VB%20Procedure" title="MySpace"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=List%20VBA%20Procedures%20by%20VBA%20Module%20and%20VB%20Procedure&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Flist-vba-procedures-by-vba-module-and-vb-procedure%2F" title="Slashdot"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Flist-vba-procedures-by-vba-module-and-vb-procedure%2F&amp;submitHeadline=List%20VBA%20Procedures%20by%20VBA%20Module%20and%20VB%20Procedure&amp;submitSummary=Mathias%20Brandewinder%20of%20Clear%20Lines%20Blog%20tweeted%20up%20Displaying%20a%20List%20of%20All%20VBA%20Procedures%20in%20an%20Excel%202007%20Workbook%20from%20the%20Ribbon%2C%20an%20article%20by%20Microsoft%27s%20Frank%20Rice%20on%20the%20MSDN%20web%20site%2C%20which%20showed%20a%20VBA%20procedure%20for%20listing%20all%20of%20the%20VBA%20&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Flist-vba-procedures-by-vba-module-and-vb-procedure%2F&amp;t=List%20VBA%20Procedures%20by%20VBA%20Module%20and%20VB%20Procedure&amp;s=Mathias%20Brandewinder%20of%20Clear%20Lines%20Blog%20tweeted%20up%20Displaying%20a%20List%20of%20All%20VBA%20Procedures%20in%20an%20Excel%202007%20Workbook%20from%20the%20Ribbon%2C%20an%20article%20by%20Microsoft%27s%20Frank%20Rice%20on%20the%20MSDN%20web%20site%2C%20which%20showed%20a%20VBA%20procedure%20for%20listing%20all%20of%20the%20VBA%20" title="Tumblr"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://peltiertech.com/WordPress/list-vba-procedures-by-vba-module-and-vb-procedure/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Robust VBA Save-As Technique</title>
		<link>http://peltiertech.com/WordPress/robust-vba-save-as-technique/</link>
		<comments>http://peltiertech.com/WordPress/robust-vba-save-as-technique/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 09:00:03 +0000</pubDate>
		<dc:creator>Jon Peltier</dc:creator>
				<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=2708</guid>
		<description><![CDATA[One of the most important things a VBA procedure can do is save a file, especially a file that&#8217;s been substantially modified by that procedure.
This functionality is even better if the user is given the opportunity to specify a path and file name.  You can simply pop up Excel&#8217;s own Save As dialog:
Application.Dialogs(xlDialogSaveAs).Show sFileName
This approach [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most important things a VBA procedure can do is save a file, especially a file that&#8217;s been substantially modified by that procedure.</p>
<p>This functionality is even better if the user is given the opportunity to specify a path and file name.  You can simply pop up Excel&#8217;s own <tt class="tt">Save As</tt> dialog:</p>
<pre class="vbasmall"><code>Application.Dialogs(xlDialogSaveAs).Show sFileName</code></pre>
<p>This approach is fine for simple applications, but it saves the file before execution returns to the calling procedure. This may not be what you want to do with the file and file name.</p>
<p>Excel&#8217;s VBA object model has a more flexible approach. The <tt class="tt">GetSaveAsFilename</tt> method opens a <tt class="tt">Save As</tt> dialog and gives the user control over directory and file name. <tt class="tt">GetSaveAsFilename</tt> does not save the file, but only retrieves the combined path and file name and returns it to the executing procedure for further use. If the user cancels, the function returns the string &#8220;False&#8221; instead of a filename.</p>
<p><span id="more-2708"></span>Below is an implementation of <tt class="tt">GetSaveAsFilename</tt> that I&#8217;ve wrapped in a function called <tt class="tt">GSAFN</tt>. The function  takes a file name and path, which are used as the defaults in the <tt class="tt">Save As</tt> dialog.  If the file name entered by the user matches an existing file name, it asks the user what to do: overwrite the existing file, enter another file name, or cancel the save operation. If the user cancels the save, <tt class="tt">GSAFN</tt> returns a zero length string.</p>
<pre class="vbasmall"><code>Function GSAFN(sFileName As String, sPathName As String) As String
  Dim sFullName As String
  Dim sPrompt As String
  Dim sCurDir As String
  Dim iOverwrite As Long

  If ActiveWorkbook Is Nothing Then GoTo ExitSub

  ' save current directory, restore it later
  sCurDir = CurDir

  ' switch to desired directory
  If Len(sPathName) &gt; 0 Then
    ChDrive sPathName
    ChDir sPathName
  End If

  ' loop until unique name is entered
  Do
    sFullName = Application.GetSaveAsFilename(sFileName, _
        "Excel Files (*.xls),*.xls", , _
        "Browse to a folder and enter a file name")

    If Len(sFullName) = 0 Then GoTo ExitSub
    If sFullName = "False" Then GoTo ExitSub

    ' if name is unique, exit loop and save file
    If Not FileExists(sFullName) Then Exit Do

    ' tell user that the filename is in use

    ' parse filename
    sFileName = FullNameToFileName(sFullName)
    sPathName = FullNameToPath(sFullName)

    ' construct message
    sPrompt = "A file named '" &amp; sFileName &amp; "' already exists in '" _
        &amp; sPathName &amp; "'"
    sPrompt = sPrompt &amp; vbNewLine &amp; vbNewLine &amp; _
        "Do you want to overwrite the existing file?"

    ' ask user what to do
    iOverwrite = MsgBox(sPrompt, vbYesNoCancel + vbQuestion, _
        "Image File Exists")

    Select Case iOverwrite
      Case vbYes
        ' overwrite existing file
        Exit Do
      Case vbNo
        ' do nothing, loop again to get new filename
      Case vbCancel
        ' bail out
        GoTo ExitSub
    End Select
  Loop

  ' finally, save the file using filename from above
  Application.DisplayAlerts = False
  ActiveWorkbook.SaveAs sFullName
  Application.DisplayAlerts = True

  GSAFN = sFullName

ExitSub:
  ' restore previous current directory
  ChDrive sCurDir
  ChDir sCurDir

End Function</code></pre>
<p>The following procedures are used in the main procedure above. The <tt class="tt">FileExists</tt> function is more flexible than simply using <tt class="tt">Dir</tt>, because using it does not reset the initial file spec used in <tt class="tt">Dir</tt>. The <tt class="tt">FullNameToFileName</tt> and <tt class="tt">FullNameToPath</tt> functions parse the combined path and file name into a separate path and file name, making the <tt class="tt">GSAFN</tt> function work more easily. They were originally written for Excel 97, before VBA had the <tt class="tt">RevInStr</tt> string function; don&#8217;t laugh at the antiquated syntax, because they still work just fine.</p>
<pre class="vbasmall"><code>Function FileExists(ByVal FileSpec As String) As Boolean
  ' Karl Peterson, Former MS VB6 MVP
  Dim Attr As Long
  ' Guard against bad FileSpec by ignoring errors
  ' retrieving its attributes.
  On Error Resume Next
  Attr = GetAttr(FileSpec)
  If Err.Number = 0 Then
    ' No error, so something was found.
    ' If Directory attribute set, then not a file.
    FileExists = Not ((Attr And vbDirectory) = vbDirectory)
  End If
End Function

Function FullNameToFileName(sFullName As String) As String
  Dim k As Integer
  Dim sTest As String
  If InStr(1, sFullName, "[") &gt; 0 Then
    k = InStr(1, sFullName, "[")
    sTest = Mid(sFullName, k + 1, InStr(1, sFullName, "]") - k - 1)
  Else
    For k = Len(sFullName) To 1 Step -1
      If Mid(sFullName, k, 1) = "\" Then Exit For
    Next k
    sTest = Mid(sFullName, k + 1, Len(sFullName) - k)
  End If
  FullNameToFileName = sTest
End Function

Function FullNameToPath(sFullName As String) As String
  ''' does not include trailing backslash
  Dim k As Integer
  For k = Len(sFullName) To 1 Step -1
    If Mid(sFullName, k, 1) = "\" Then Exit For
  Next k
  If k &lt; 1 Then
    FullNameToPath = ""
  Else
    FullNameToPath = Mid(sFullName, 1, k - 1)
  End If
End Function</code></pre>
<p><tt class="tt">GSAFN</tt> is called as follows:</p>
<pre class="vbasmall"><code>Sub TestGSAFN()
  Dim sFile As String
  sFile = GSAFN("testfile.xls", "C:\Temp")
  If Len(sFile) &gt; 0 Then
    MsgBox "File successfully saved"
  Else
    MsgBox "File was not saved"
  End If
End Sub</code></pre>
<p><tt class="tt">GSAFN</tt> and the supporting functions are so helpful that I include them in a general Tools module which I drop into each new project I develop.</p>
<p>Peltier Technical Services, Inc., Copyright © 2010.<br /> <br /><span style="font: 80% Verdana,Tahoma,Arial,sans-serif;">Licensed under a <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/" rel="nofollow" rel="license" >Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.<br /> <br />
<a href="http://www.exceluser.com/cmd.asp?Clk=1374689" rel="nofollow" ><IMG SRC="http://www.exceluser.com/images/info/pub/info_dash_c02.gif" ALT="Learn how to create Excel dashboards." WIDTH="468" HEIGHT="60" border=0></a><br />
<br /><img src="http://www.exceluser.com/cmd.asp?Imp=1374689" width="0" height="0" border="0"></p>



Bookmark and share this entry:


	<a rel="nofollow"  href="http://twitter.com/home?status=Robust%20VBA%20Save-As%20Technique%20-%20http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frobust-vba-save-as-technique%2F" title="Twitter"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frobust-vba-save-as-technique%2F&amp;title=Robust%20VBA%20Save-As%20Technique&amp;bodytext=One%20of%20the%20most%20important%20things%20a%20VBA%20procedure%20can%20do%20is%20save%20a%20file%2C%20especially%20a%20file%20that%27s%20been%20substantially%20modified%20by%20that%20procedure.%0D%0A%0D%0AThis%20functionality%20is%20even%20better%20if%20the%20user%20is%20given%20the%20opportunity%20to%20specify%20a%20path%20and%20file%20name." title="Digg"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frobust-vba-save-as-technique%2F&amp;t=Robust%20VBA%20Save-As%20Technique" title="Facebook"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frobust-vba-save-as-technique%2F&amp;title=Robust%20VBA%20Save-As%20Technique&amp;source=Peltier+Tech+Blog+Peltier+Tech+Excel+Charts+and+Programming+Blog&amp;summary=One%20of%20the%20most%20important%20things%20a%20VBA%20procedure%20can%20do%20is%20save%20a%20file%2C%20especially%20a%20file%20that%27s%20been%20substantially%20modified%20by%20that%20procedure.%0D%0A%0D%0AThis%20functionality%20is%20even%20better%20if%20the%20user%20is%20given%20the%20opportunity%20to%20specify%20a%20path%20and%20file%20name." title="LinkedIn"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frobust-vba-save-as-technique%2F&amp;title=Robust%20VBA%20Save-As%20Technique&amp;notes=One%20of%20the%20most%20important%20things%20a%20VBA%20procedure%20can%20do%20is%20save%20a%20file%2C%20especially%20a%20file%20that%27s%20been%20substantially%20modified%20by%20that%20procedure.%0D%0A%0D%0AThis%20functionality%20is%20even%20better%20if%20the%20user%20is%20given%20the%20opportunity%20to%20specify%20a%20path%20and%20file%20name." title="del.icio.us"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frobust-vba-save-as-technique%2F" title="Technorati"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frobust-vba-save-as-technique%2F&amp;title=Robust%20VBA%20Save-As%20Technique" title="StumbleUpon"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frobust-vba-save-as-technique%2F&amp;title=Robust%20VBA%20Save-As%20Technique&amp;annotation=One%20of%20the%20most%20important%20things%20a%20VBA%20procedure%20can%20do%20is%20save%20a%20file%2C%20especially%20a%20file%20that%27s%20been%20substantially%20modified%20by%20that%20procedure.%0D%0A%0D%0AThis%20functionality%20is%20even%20better%20if%20the%20user%20is%20given%20the%20opportunity%20to%20specify%20a%20path%20and%20file%20name." title="Google Bookmarks"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frobust-vba-save-as-technique%2F&amp;title=Robust%20VBA%20Save-As%20Technique" title="Reddit"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frobust-vba-save-as-technique%2F&amp;t=Robust%20VBA%20Save-As%20Technique" title="MySpace"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Robust%20VBA%20Save-As%20Technique&amp;url=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frobust-vba-save-as-technique%2F" title="Slashdot"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frobust-vba-save-as-technique%2F&amp;submitHeadline=Robust%20VBA%20Save-As%20Technique&amp;submitSummary=One%20of%20the%20most%20important%20things%20a%20VBA%20procedure%20can%20do%20is%20save%20a%20file%2C%20especially%20a%20file%20that%27s%20been%20substantially%20modified%20by%20that%20procedure.%0D%0A%0D%0AThis%20functionality%20is%20even%20better%20if%20the%20user%20is%20given%20the%20opportunity%20to%20specify%20a%20path%20and%20file%20name.&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fpeltiertech.com%2FWordPress%2Frobust-vba-save-as-technique%2F&amp;t=Robust%20VBA%20Save-As%20Technique&amp;s=One%20of%20the%20most%20important%20things%20a%20VBA%20procedure%20can%20do%20is%20save%20a%20file%2C%20especially%20a%20file%20that%27s%20been%20substantially%20modified%20by%20that%20procedure.%0D%0A%0D%0AThis%20functionality%20is%20even%20better%20if%20the%20user%20is%20given%20the%20opportunity%20to%20specify%20a%20path%20and%20file%20name." title="Tumblr"><img src="http://peltiertech.com/WordPress/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://peltiertech.com/WordPress/robust-vba-save-as-technique/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>
