<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Roy MacLean&#039;s VBA Blog</title>
	<atom:link href="http://roymacleanvba.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://roymacleanvba.wordpress.com</link>
	<description>Miscellanea on VBA, Office Apps and XML Documentation</description>
	<lastBuildDate>Fri, 23 Dec 2011 17:18:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='roymacleanvba.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Roy MacLean&#039;s VBA Blog</title>
		<link>http://roymacleanvba.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://roymacleanvba.wordpress.com/osd.xml" title="Roy MacLean&#039;s VBA Blog" />
	<atom:link rel='hub' href='http://roymacleanvba.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Signing Off&#8230;</title>
		<link>http://roymacleanvba.wordpress.com/2011/12/23/signing-off/</link>
		<comments>http://roymacleanvba.wordpress.com/2011/12/23/signing-off/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 17:18:00 +0000</pubDate>
		<dc:creator>Roy MacLean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://roymacleanvba.wordpress.com/?p=601</guid>
		<description><![CDATA[Thanks to all of you who have visited this blog in 2011, and have continued to make comments. However, I need to point out that I&#8217;m no longer actively blogging here, so this site is now just for reference. I hope you continue to find it useful. At the start of the year I started [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=601&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Thanks to all of you who have visited this blog in 2011, and have continued to make comments. However, I need to point out that I&#8217;m no longer actively blogging here, so this site is now just for reference. I hope you continue to find it useful.</p>
<p>At the start of the year I started a new  job which has taken me away from Excel, Access and VBA. As some of my later posts indicated (see the tag cloud), I am now in the world of <a href="http://dita.xml.org/book/getting-started">DITA XML documentation</a>, in both a technical and an authoring capacity. My current investigations concern:</p>
<ul>
<li>storing document components in an XML database</li>
<li>categorizing document components, on multiple dimensions, using internal meta-data</li>
<li>constructing documentation build manifests (DITA maps) using high-level queries (in XQuery)</li>
</ul>
<p>If that sounds interesting, then contact me via the About page.</p>
<p>Enjoy your coding, in whatever language!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/roymacleanvba.wordpress.com/601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/roymacleanvba.wordpress.com/601/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/roymacleanvba.wordpress.com/601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/roymacleanvba.wordpress.com/601/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/roymacleanvba.wordpress.com/601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/roymacleanvba.wordpress.com/601/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/roymacleanvba.wordpress.com/601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/roymacleanvba.wordpress.com/601/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/roymacleanvba.wordpress.com/601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/roymacleanvba.wordpress.com/601/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/roymacleanvba.wordpress.com/601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/roymacleanvba.wordpress.com/601/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/roymacleanvba.wordpress.com/601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/roymacleanvba.wordpress.com/601/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=601&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://roymacleanvba.wordpress.com/2011/12/23/signing-off/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">roymacleanvba</media:title>
		</media:content>
	</item>
		<item>
		<title>Still here&#8230;</title>
		<link>http://roymacleanvba.wordpress.com/2011/03/05/still-here/</link>
		<comments>http://roymacleanvba.wordpress.com/2011/03/05/still-here/#comments</comments>
		<pubDate>Sat, 05 Mar 2011 18:06:43 +0000</pubDate>
		<dc:creator>Roy MacLean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://roymacleanvba.wordpress.com/?p=592</guid>
		<description><![CDATA[Sorry the postings have been a bit thin on the ground since the New Year. Rather unexpectedly some freelance work has developed into a permanent position. I am now in a role which is primarily focused on DITA/XML documentation, for a company that produces a Payments Processing system (Direct Debits and such like). The challenge [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=592&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sorry the postings have been a bit thin on the ground since the New Year. Rather unexpectedly some freelance work has developed into a permanent position. I am now in a role which is primarily focused on <a href="http://roymacleanvba.wordpress.com/2009/08/25/digression-on-documentation-dita/">DITA/XML documentation</a>, for a company that produces a Payments Processing system (Direct Debits and such like). The challenge is to make the documentation scheme fit the highly modular nature of the system, and the core product &#8211;&gt; client customization delivery process.</p>
<p>While Excel/VBA will still be in the mix, it won&#8217;t be central to what I&#8217;m doing. I&#8217;ll try to carry on posting as and when, so keep dropping by.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/roymacleanvba.wordpress.com/592/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/roymacleanvba.wordpress.com/592/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/roymacleanvba.wordpress.com/592/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/roymacleanvba.wordpress.com/592/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/roymacleanvba.wordpress.com/592/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/roymacleanvba.wordpress.com/592/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/roymacleanvba.wordpress.com/592/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/roymacleanvba.wordpress.com/592/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/roymacleanvba.wordpress.com/592/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/roymacleanvba.wordpress.com/592/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/roymacleanvba.wordpress.com/592/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/roymacleanvba.wordpress.com/592/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/roymacleanvba.wordpress.com/592/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/roymacleanvba.wordpress.com/592/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=592&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://roymacleanvba.wordpress.com/2011/03/05/still-here/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">roymacleanvba</media:title>
		</media:content>
	</item>
		<item>
		<title>Analysing Cross-references Between Documents</title>
		<link>http://roymacleanvba.wordpress.com/2011/01/28/analysing-cross-references-between-documents/</link>
		<comments>http://roymacleanvba.wordpress.com/2011/01/28/analysing-cross-references-between-documents/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 14:36:02 +0000</pubDate>
		<dc:creator>Roy MacLean</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[DITA]]></category>
		<category><![CDATA[pivot]]></category>
		<category><![CDATA[XQuery]]></category>

		<guid isPermaLink="false">http://roymacleanvba.wordpress.com/?p=586</guid>
		<description><![CDATA[I have recently been working on a set of about 200 Use Case documents, converting them into DITA - an XML-based structured document format. In the body text of a Use Case, there can be cross-references to other Use cases &#8211; so we have a many-to-many relationship between Use Cases (just as we could between [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=586&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have recently been working on a set of about 200 Use Case documents, converting them into <a href="http://dita.xml.org/book/getting-started">DITA </a>- an XML-based structured document format. In the body text of a Use Case, there can be cross-references to other Use cases &#8211; so we have a many-to-many relationship between Use Cases (just as we could between any type of document). It&#8217;s interesting to analyse this relationship, to see which Use Cases have lots of outgoing references, and which Use Cases are referenced by many other Use Cases.</p>
<p>This kind of totalling is Pivot Table territory. So the question arises of how to contruct the basic data about the cross-references &#8211; a table of A-references-B records &#8211; and how to get it into Excel.</p>
<p>A key advantage of XML-based documents is that you can import them into an XML database and run queries over them, where the queries are written in XQuery. Such queries can generate output as XML, HTML or plain text. For our purpose, a simple route is to output an HTML table. This can then be imported by Excel via &gt;Get External Data &gt;From Web. The URL for the import points to our XQuery file, within the database server:</p>
<blockquote><p>http://roy-laptop:18080/qizx/xqs/ucrefs.xq</p></blockquote>
<p>Here, the database is XMLMind&#8217;s <a href="http://www.xmlmind.com/qizx/">Qizx</a>, running in server mode (locally on my laptop, in this case). This URL can be used like any other in a browser interface, with the results of the query being displayed within the browser. In our case, we are going to give the URL to Excel.</p>
<p>Here&#8217;s the code of the query:</p>
<p><pre class="brush: plain;">
xquery version &quot;1.0&quot;;
declare option output:method &quot;html&quot;;

declare variable $ucs := collection(&quot;/UC&quot;);

declare function local:uc_refs()
{
  for $ucref in $ucs//uc-ref
  let $file := document-uri(root($ucref))
  let $ucreftext := $ucref/text()
  order by $file
  return
  &lt;tr&gt;&lt;td&gt;{$file}&lt;/td&gt;&lt;td&gt;{$ucreftext}&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;
};

let $ucrefs := local:uc_refs()
return
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
  &lt;head&gt;
    &lt;title&gt;UC References&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;table&gt;
      &lt;thead&gt;
	    &lt;tr&gt;&lt;td&gt;Source&lt;/td&gt;&lt;td&gt;Target&lt;/td&gt;&lt;td&gt;Token&lt;/td&gt;&lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
	    {$ucrefs}
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre></p>
<p>Variables start with $. The function <em>collection </em>(line 4) scopes the query to a particular directory tree of document files. The expression &#8216;$ucs//uc-ref&#8217; binds to each occurrence of the &lt;uc-ref&gt; element, anywhere in the collection of documents. $file is the document in which a &lt;uc-ref&gt; is found. The third column of the table (Token) is just the number 1 &#8211; this gives me some data for the pivot table to sum.</p>
<p>Now we can do the import into Excel:</p>
<p><a href="http://roymacleanvba.files.wordpress.com/2011/01/webimport.png"><img class="alignnone size-full wp-image-587" title="WebImport" src="http://roymacleanvba.files.wordpress.com/2011/01/webimport.png?w=500&#038;h=336" alt="" width="500" height="336" /></a></p>
<p>Finally, I can insert a pivot table based on this data, subtotalling by either Source or Target, or putting both dimensions on the same axis. I love it when stuff just works&#8230;</p>
<p>Out of curiosity, I ran the import with the macro recorder on, to see what the VBA looks like:</p>
<p><pre class="brush: vb;">
Sub Import()
    With ActiveSheet.QueryTables.Add( _
        Connection:= _
            &quot;URL;http://roy-laptop:18080/qizx/xq/ucrefs.xq&quot;,
            Destination:=Range (&quot;$A$1&quot;))
        .Name = &quot;ucrefs.xq&quot;
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
End Sub
</pre></p>
<p>So it&#8217;s just creation of a QueryTable, with the URL given as a Connection string. The <em>WebSelectionType </em>property is &#8216;all tables&#8217;, although I thought I clicked the lower of the two yellow arrows in the Import dialog. Clearly, we could wrap this up a bit more: selecting from a list of queries, creating a new Worksheet, etc.</p>
<p>Having established the basic XML &#8211;&gt; XQuery &#8211;&gt; HTML Table &#8211;&gt; Excel/VBA architecture, I think I&#8217;ll experiment more with this in due course.</p>
<p>Incidentally, this is my 100th post (Rah! Rah!), having taken almost exactly two years. And most enjoyable it&#8217;s been &#8211; at least for me <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/roymacleanvba.wordpress.com/586/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/roymacleanvba.wordpress.com/586/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/roymacleanvba.wordpress.com/586/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/roymacleanvba.wordpress.com/586/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/roymacleanvba.wordpress.com/586/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/roymacleanvba.wordpress.com/586/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/roymacleanvba.wordpress.com/586/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/roymacleanvba.wordpress.com/586/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/roymacleanvba.wordpress.com/586/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/roymacleanvba.wordpress.com/586/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/roymacleanvba.wordpress.com/586/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/roymacleanvba.wordpress.com/586/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/roymacleanvba.wordpress.com/586/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/roymacleanvba.wordpress.com/586/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=586&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://roymacleanvba.wordpress.com/2011/01/28/analysing-cross-references-between-documents/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">roymacleanvba</media:title>
		</media:content>

		<media:content url="http://roymacleanvba.files.wordpress.com/2011/01/webimport.png" medium="image">
			<media:title type="html">WebImport</media:title>
		</media:content>
	</item>
		<item>
		<title>An Alternative to VBA in Excel?</title>
		<link>http://roymacleanvba.wordpress.com/2011/01/26/an-alternative-to-vba-in-excel/</link>
		<comments>http://roymacleanvba.wordpress.com/2011/01/26/an-alternative-to-vba-in-excel/#comments</comments>
		<pubDate>Wed, 26 Jan 2011 17:50:06 +0000</pubDate>
		<dc:creator>Roy MacLean</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Non-VBA]]></category>

		<guid isPermaLink="false">http://roymacleanvba.wordpress.com/?p=582</guid>
		<description><![CDATA[Back last year, Gareth Hayter of Slyce Software emailed me about VScript, an alternative to VBA for writing functions and macros in Excel. Unfortunately, for various reasons, I have not been able to look into it in any detail, but it certainly sounds interesting. VScript is based on Excel-Dna, which is a project to integrate [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=582&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Back last year, Gareth Hayter of Slyce Software emailed me about <a href="http://www.slyce.com/vscript/">VScript</a>, an alternative to VBA for writing functions and macros in Excel. Unfortunately, for various reasons, I have not been able to look into it in any detail, but it certainly sounds interesting.</p>
<p>VScript is based on <a href="http://exceldna.codeplex.com/">Excel-Dna</a>, which is a project to integrate .NET into Excel. The aim is thus to allow you to write functions and macros in C# or VB.Net &#8211; so, presumably it is aimed at developers familiar with those languages, and preferring them over VBA. Code is claimed to run considerably faster than VBA (not hard to believe).  VScript provides an IDE integrated with Excel, as with VBA. You can use VScript to create stand-alone XLL add-ins, and digitally sign these.</p>
<p>What about <a href="http://en.wikipedia.org/wiki/Visual_Studio_Tools_for_Office">VSTO</a>? Gareth says:</p>
<blockquote><p>VScript is different from VSTO (Visual Studio Tools for Office) in many ways:</p>
<ul>
<li><strong>VSTO is for professional programmers:</strong> It can be complex and confusing                             to use and requires a lot of time, effort and money to learn.</li>
<li><strong>VSTO is expensive:</strong> You need to buy Visual Studio® which starts                             at $799.</li>
<li><strong>VSTO is not built into Excel®:</strong> It is an external program and                             works in a very different way from VBA.</li>
<li><strong>VSTO projects are complicated to deploy:</strong> VSTO is not integrated                             into Excel, which means that it&#8217;s difficult to make a few changes and test them                             quickly. It requires ClickOnce deployment.</li>
<li><strong>VSTO cannot create User-Defined Functions (UDFs):</strong> With VSTO, you                             can&#8217;t create functions that you can use in a similar way to SUM() and AVG().</li>
</ul>
</blockquote>
<p>One to watch &#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/roymacleanvba.wordpress.com/582/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/roymacleanvba.wordpress.com/582/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/roymacleanvba.wordpress.com/582/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/roymacleanvba.wordpress.com/582/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/roymacleanvba.wordpress.com/582/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/roymacleanvba.wordpress.com/582/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/roymacleanvba.wordpress.com/582/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/roymacleanvba.wordpress.com/582/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/roymacleanvba.wordpress.com/582/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/roymacleanvba.wordpress.com/582/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/roymacleanvba.wordpress.com/582/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/roymacleanvba.wordpress.com/582/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/roymacleanvba.wordpress.com/582/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/roymacleanvba.wordpress.com/582/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=582&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://roymacleanvba.wordpress.com/2011/01/26/an-alternative-to-vba-in-excel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">roymacleanvba</media:title>
		</media:content>
	</item>
		<item>
		<title>Moving Data Out of Outlook &#8211; part 2</title>
		<link>http://roymacleanvba.wordpress.com/2011/01/02/moving-data-out-of-outlook-part-2/</link>
		<comments>http://roymacleanvba.wordpress.com/2011/01/02/moving-data-out-of-outlook-part-2/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 18:09:43 +0000</pubDate>
		<dc:creator>Roy MacLean</dc:creator>
				<category><![CDATA[VBA Projects]]></category>
		<category><![CDATA[Outlook]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://roymacleanvba.wordpress.com/?p=576</guid>
		<description><![CDATA[Happy and code-full 2011! In an earlier post, I was considering exporting my Outlook contacts as XHTML pages, and accessing these as a repository of free-format, but queryable, documents. After some time out for Christmas and New Year, not to mention my family&#8217;s seasonal cough-fest, I can report back. I haven&#8217;t attempted a comprehensive export [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=576&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Happy and code-full 2011!</p>
<p>In an <a href="http://roymacleanvba.wordpress.com/2010/11/21/moving-data-out-of-outlook/">earlier post</a>, I was considering exporting my Outlook contacts as XHTML pages, and accessing these as a repository of free-format, but queryable, documents. After some time out for Christmas and New Year, not to mention my family&#8217;s seasonal cough-fest, I can report back.</p>
<p>I haven&#8217;t attempted a comprehensive export of all contact attributes, just the standard ones that I typically use. This still leaves information in the Contact&#8217;s body section, but I&#8217;ll migrate that manually, as and when.</p>
<p>Here&#8217;s an example contact page:</p>
<p><a href="http://roymacleanvba.files.wordpress.com/2011/01/contactsexportpage.png"><img class="alignnone size-full wp-image-577" title="ContactsExportPage" src="http://roymacleanvba.files.wordpress.com/2011/01/contactsexportpage.png?w=500" alt=""   /></a></p>
<p>I just grabbed a standard style sheet, so the formatting is not up to much (for example, the cell text middle-aligns vertically, as you can see with &#8220;Address&#8221;).</p>
<p>In terms of the VBA code, all we need is an adapter class, <em>ContactPage</em>. Instances of this are created for each <em>ContactItem </em>that we export. A <em>ContactPage </em>is responsible for building the XHTML string corresponding to the <em>ContactItem</em>, and writing it out to a text file. Here&#8217;s the root procedure:</p>
<p><pre class="brush: vb;">
Const outdir As String = &quot;C:\Temp\Contacts&quot;

Sub ExportContacts()
  Dim allcontacts As Items
  Set allcontacts = Session.Folders(&quot;Personal Folders&quot;). _
                             Folders(&quot;Contacts&quot;).Items

  MsgBox &quot;Exporting &quot; &amp; allcontacts.Count &amp; &quot; Contacts&quot;

  Dim cn As ContactItem  'Outlook class
  Dim cp As ContactPage  'Custom class
  For Each cn In allcontacts
    Set cp = New ContactPage
    Set cp.Contact = cn    'Property Set
    cp.OutputToFile outdir
  Next
End Sub
</pre></p>
<p><em>ContactPage </em>has a function for <em>PageTitle</em>, which is taken from the <em>ContactItem</em>&#8216;s Company or Full Name (in that order of preference). Functions <em>PageId </em>and <em>PageFile </em>are based on this (with a bit of cleaning up to remove characters such as &#8216;/&#8217;).</p>
<p>The sub <em>OutputToFile </em>uses the Microsoft Scripting Runtime library, specifically <em>FileSystemObject</em> and <em>TextStream</em>. You need to load the Scripting library manually, via &gt;Tools &gt;References.</p>
<p>The rest of ContactPage&#8217;s features are just functions that generate elements in the XHTML hierarchy. For example:</p>
<p><pre class="brush: vb;">
Public Function XhtmlPage() As String
'The XHTML representation of cp_contact
    XhtmlPage = Header_ &amp; vbCrLf &amp; _
                Html_
End Function

'...

Public Function Html_() As String
    Html_ = &quot;&lt;html id=&quot; &amp; Chr(34) &amp; PageId &amp; Chr(34) '&amp; ...
    Html_ = Html_ &amp; vbCrLf &amp; _
            Head_ &amp; vbCrLf &amp; _
            Body_ &amp; vbCrLf &amp; _
            &quot;&lt;/html&gt;&quot;
End Function

Public Function Body_() As String
    Body_ = &quot;&lt;body&gt;&quot; &amp; vbCrLf &amp; _
            &quot;&lt;h1&gt;&quot; &amp; PageTitle &amp; &quot;&lt;/h1&gt;&quot; &amp; vbCrLf &amp; _
            Company_table_ &amp; vbCrLf &amp; _
            Person_table_(1) &amp; vbCrLf &amp; _
            Person_table_(2) &amp; vbCrLf &amp; _
            Person_table_(3) &amp; vbCrLf &amp; _
            Categories_ul_ &amp; vbCrLf &amp; _
            &quot;&lt;/body&gt;&quot;
End Function

'...

Public Function LastName_td_() As String
    LastName_td_ = &quot;&lt;td class=&quot; &amp; Chr(34) &amp; &quot;LastName&quot; &amp; Chr(34) &amp; &quot;&gt;&quot; &amp; _
     cp_contact.LastName &amp; &quot;&lt;/td&gt;&quot;
End Function
</pre></p>
<p>The lowest level functions, typically for &lt;td&gt; elements, access the <em>ContactItem</em>&#8216;s properties. As you can see, there are a lot of quotation characters (Chr(34)) in XHTML. The trailing-underscore convention for the function names was so that I could call the functions after the XHTML tags they generate &#8211; without the underscore I got a name clash with something existing.</p>
<p>Minor complications where the Contacts folder contains Distribution Lists (class <em>DistListItem</em>), which is a different class from <em>ContactItem</em> &#8211; that is, a <em>MAPIFolder.Items</em> is a heterogeneous Collection. This makes the For Each loop throw a type mismatch error, although you can resume execution (&gt;Debug, &gt;Run).</p>
<p>Also a slight issue with duplicate filenames, since the file output overwrites by default. I used <em>Round(Rnd * 1000, 0)</em> to generate a temporary disambiguating suffiix for the filename.</p>
<p>Here&#8217;s the <a href="http://roymaclean-it.co.uk/vbadownload/ContactPage.cls">Class Module</a> for <em>ContactPage</em>.</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/roymacleanvba.wordpress.com/576/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/roymacleanvba.wordpress.com/576/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/roymacleanvba.wordpress.com/576/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/roymacleanvba.wordpress.com/576/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/roymacleanvba.wordpress.com/576/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/roymacleanvba.wordpress.com/576/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/roymacleanvba.wordpress.com/576/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/roymacleanvba.wordpress.com/576/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/roymacleanvba.wordpress.com/576/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/roymacleanvba.wordpress.com/576/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/roymacleanvba.wordpress.com/576/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/roymacleanvba.wordpress.com/576/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/roymacleanvba.wordpress.com/576/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/roymacleanvba.wordpress.com/576/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=576&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://roymacleanvba.wordpress.com/2011/01/02/moving-data-out-of-outlook-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">roymacleanvba</media:title>
		</media:content>

		<media:content url="http://roymacleanvba.files.wordpress.com/2011/01/contactsexportpage.png" medium="image">
			<media:title type="html">ContactsExportPage</media:title>
		</media:content>
	</item>
		<item>
		<title>Diff for Access Tables</title>
		<link>http://roymacleanvba.wordpress.com/2010/12/08/diff-for-access-tables/</link>
		<comments>http://roymacleanvba.wordpress.com/2010/12/08/diff-for-access-tables/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 16:42:19 +0000</pubDate>
		<dc:creator>Roy MacLean</dc:creator>
				<category><![CDATA[VBA Projects]]></category>
		<category><![CDATA[Access]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://roymacleanvba.wordpress.com/?p=568</guid>
		<description><![CDATA[I haven&#8217;t had time to progress the Outlook Contact Export, so here is a minor digression. Suppose that I have two Access tables each containing records that represent the same entities &#8211; Orders, say. These two sets of equivalent records come from different sources: maybe Orders as received, and Orders as dispatched. I want to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=568&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t had time to progress the <a href="http://roymacleanvba.wordpress.com/2010/11/21/moving-data-out-of-outlook/">Outlook Contact Export</a>, so here is a minor digression.</p>
<p>Suppose that I have two Access tables each containing records that represent the same entities &#8211; Orders, say. These two sets of equivalent records come from different sources: maybe Orders as received, and Orders as dispatched. I want to cross-check certain fields for equivalent records &#8211; say, that order-quantity received and order-quantity dispatched are the same &#8211; and flag any mismatches.</p>
<p>Here are two tables:</p>
<p><a href="http://roymacleanvba.files.wordpress.com/2010/12/diff_table1.png"><img class="alignnone size-full wp-image-569" title="Diff_Table1" src="http://roymacleanvba.files.wordpress.com/2010/12/diff_table1.png?w=500" alt=""   /></a></p>
<p><a href="http://roymacleanvba.files.wordpress.com/2010/12/diff_table2.png"><img class="alignnone size-full wp-image-570" title="Diff_Table2" src="http://roymacleanvba.files.wordpress.com/2010/12/diff_table2.png?w=500" alt=""   /></a></p>
<p>I want to check the equivalence of columns B and C. There are differences in B/C for the second and fourth records, and an extra record in the second table.</p>
<p>Note that the IDs are counters, but are not necessarily the same, so I can not do a Join of the two tables. The tables are assumed to represent equivalent sets of records &#8211; maybe for the same period &#8211; so they could be queries on underlying cumulative tables.</p>
<p>It&#8217;s not apparent to me how you could do this using queries. If we could join the tables together, then for numerical values I suppose that we could subtract one field from the other, and check for non-zero differences.</p>
<p>However, a more generic solution is to suck the relevant columns into two Recordsets, using a simple SELECT query as the Source, and then iterate through records and fields, comparing values. Differences can be logged in some way:</p>
<ul>
<li>If we expect only rare differences, then we could build up a log String, and display this at the end of the check:<br />
<a href="http://roymacleanvba.files.wordpress.com/2010/12/diff_msgbox.png"><img class="alignnone size-full wp-image-571" title="Diff_MsgBox" src="http://roymacleanvba.files.wordpress.com/2010/12/diff_msgbox.png?w=500" alt=""   /></a></li>
<li>If we expect substantial differences, we could base an output Recordset on a temporary table, and write message-records into it.</li>
</ul>
<p>I&#8217;ve adopted the first approach, for simplicity.</p>
<p>Here&#8217;s a <a href="http://roymaclean-it.co.uk/vbadownload/RecsetDiff.bas">code module</a>, and the <a href="http://roymaclean-it.co.uk/vbadownload/Diff.mdb">database </a>(2003 .mdb) with test tables. There&#8217;s no user interface: <em>RunDiff </em>is run directly from within VBA.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/roymacleanvba.wordpress.com/568/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/roymacleanvba.wordpress.com/568/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/roymacleanvba.wordpress.com/568/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/roymacleanvba.wordpress.com/568/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/roymacleanvba.wordpress.com/568/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/roymacleanvba.wordpress.com/568/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/roymacleanvba.wordpress.com/568/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/roymacleanvba.wordpress.com/568/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/roymacleanvba.wordpress.com/568/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/roymacleanvba.wordpress.com/568/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/roymacleanvba.wordpress.com/568/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/roymacleanvba.wordpress.com/568/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/roymacleanvba.wordpress.com/568/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/roymacleanvba.wordpress.com/568/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=568&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://roymacleanvba.wordpress.com/2010/12/08/diff-for-access-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">roymacleanvba</media:title>
		</media:content>

		<media:content url="http://roymacleanvba.files.wordpress.com/2010/12/diff_table1.png" medium="image">
			<media:title type="html">Diff_Table1</media:title>
		</media:content>

		<media:content url="http://roymacleanvba.files.wordpress.com/2010/12/diff_table2.png" medium="image">
			<media:title type="html">Diff_Table2</media:title>
		</media:content>

		<media:content url="http://roymacleanvba.files.wordpress.com/2010/12/diff_msgbox.png" medium="image">
			<media:title type="html">Diff_MsgBox</media:title>
		</media:content>
	</item>
		<item>
		<title>Moving Data Out of Outlook</title>
		<link>http://roymacleanvba.wordpress.com/2010/11/21/moving-data-out-of-outlook/</link>
		<comments>http://roymacleanvba.wordpress.com/2010/11/21/moving-data-out-of-outlook/#comments</comments>
		<pubDate>Sun, 21 Nov 2010 17:17:17 +0000</pubDate>
		<dc:creator>Roy MacLean</dc:creator>
				<category><![CDATA[VBA Projects]]></category>
		<category><![CDATA[Outlook]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://roymacleanvba.wordpress.com/?p=562</guid>
		<description><![CDATA[I&#8217;ve felt uneasy for a while that important data &#8211; for example, my Contacts &#8211; is sitting in Outlook, in an enormous and opaque database file (.pst). Okay, it&#8217;s backed up, but if it became &#8216;corrupted&#8217; and wouldn&#8217;t open, then I have no way of recovering the data, that I know of. Why should I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=562&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve felt uneasy for a while that important data &#8211; for example, my Contacts &#8211; is sitting in Outlook, in an enormous and opaque database file (.pst). Okay, it&#8217;s backed up, but if it became &#8216;corrupted&#8217; and wouldn&#8217;t open, then I have no way of recovering the data, that I know of. Why should I have to open Outlook, just to find someone&#8217;s website, or phone number? The whole idea of organizing your life within a single application seems terribly outmoded. I just want a mail client that handles message send and receipt; all the information I want to be in the &#8216;outside world&#8217;.</p>
<p>Retrieving data can be pretty painful too. I&#8217;ve just clicked on the &#8216;Activities&#8217; tab of a contact, and it&#8217;s taken over 2 minutes to come back with about 20 items. While there is free-text search, there is no proper query access.</p>
<p>Outlook&#8217;s data model is baroquely large &#8211; a futile attempt to cover all possibilities. I&#8217;m looking at the class <em>ContactItem</em>, and it has nearly 150 attributes. I can have <em>NickName</em>, <em>TelexNumber </em>(telex?) and <em>YomiFirstName </em>(something Japanese); but I can only have three email addresses and one webiste URL.</p>
<p>So what&#8217;s the alternative? What I&#8217;d like is for each item (contact, whatever) to be a web page in a local (private) website. New pages could be created, edited and added as necessary. The information is all fully accessible using basic or more sophisticated editors. Website and mailto links work normally &#8211; the latter opening a mail client, as usual.</p>
<p>As it happens I&#8217;m using a <a href="http://www.xmlmind.com/docrep/">document repository</a> for XML documents, including those in XHTML. This runs on a Jetty server, at a localhost port. The repository can be browsed as a directory hierarchy, free-text searched, and queried (using XQuery). Because the repository is fully indexed, the search and query are very fast. I can create/edit documents in the repository directly, without the need to export/import, using a WebDAV-enabled editor.</p>
<p>So, to populate the repository initially, I would need to export my existing contacts from Outlook in some way. Exporting items as XML or HTML directly is beyond Outlook (up to and including v2007). So I&#8217;m thinking that I could write a custom export to XHTML &#8211; nothing complicated, just a simple page with tables. Elements, such as the table cells, would be given standard <em>id </em>attributes to indicate the content type &#8211; such as &#8216;company&#8217;, &#8216;address&#8217;; these can then be used in queries, analogously to column names in SQL.</p>
<p>In terms of the design, I&#8217;m wondering about a custom class, say <em>ContactAdapter</em>, which would wrap a <em>ContactItem</em>, and build the complete XHTML string, and write it to a file (using the Scripting library for the file access). I&#8217;ve not done anything like this before, so we&#8217;ll see. I suppose that I could export the data to Excel, and work on it there, but dealing with rows and columns is less direct than working with the actual <em>ContactItem </em>objects in Outlook.</p>
<p>More anon&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/roymacleanvba.wordpress.com/562/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/roymacleanvba.wordpress.com/562/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/roymacleanvba.wordpress.com/562/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/roymacleanvba.wordpress.com/562/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/roymacleanvba.wordpress.com/562/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/roymacleanvba.wordpress.com/562/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/roymacleanvba.wordpress.com/562/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/roymacleanvba.wordpress.com/562/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/roymacleanvba.wordpress.com/562/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/roymacleanvba.wordpress.com/562/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/roymacleanvba.wordpress.com/562/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/roymacleanvba.wordpress.com/562/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/roymacleanvba.wordpress.com/562/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/roymacleanvba.wordpress.com/562/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=562&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://roymacleanvba.wordpress.com/2010/11/21/moving-data-out-of-outlook/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">roymacleanvba</media:title>
		</media:content>
	</item>
		<item>
		<title>Spreadsheets in XML &#8211; Part 2</title>
		<link>http://roymacleanvba.wordpress.com/2010/11/08/spreadsheets-in-xml-part-2/</link>
		<comments>http://roymacleanvba.wordpress.com/2010/11/08/spreadsheets-in-xml-part-2/#comments</comments>
		<pubDate>Mon, 08 Nov 2010 16:42:09 +0000</pubDate>
		<dc:creator>Roy MacLean</dc:creator>
				<category><![CDATA[Non-VBA]]></category>
		<category><![CDATA[DITA]]></category>
		<category><![CDATA[Formulas]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XQuery]]></category>

		<guid isPermaLink="false">http://roymacleanvba.wordpress.com/?p=549</guid>
		<description><![CDATA[In the previous post, I was looking at the &#8216;spreadsheet extensions&#8217; provided by XMLMind’s XML Editor (XXE). This allows XPath-based formulas to be inserted into XML documents, not only in tabular elements, but also in free text. As an example, I mocked up some invoices. An invoice is a good example of a hybrid document: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=549&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://roymacleanvba.wordpress.com/2010/11/01/spreadsheets-in-xml/">previous post</a>, I was looking at the &#8216;spreadsheet extensions&#8217; provided by <a href="http://www.xmlmind.com/xmleditor/">XMLMind’s XML Editor (XXE)</a>. This allows XPath-based formulas to be inserted into XML documents, not only in tabular elements, but also in free text.</p>
<p>As an example, I mocked up some invoices. An invoice is a good example of a hybrid document: we want to print it out (or PDF it) as a nicely formatted document; there are calculated and looked-up elements in the manner of a spreadsheet; we want the whole set of invoices to be queryable subsequently, in the manner of a database.</p>
<p>Here&#8217;s an invoice, as a DITA document, shown in XXE:</p>
<p><a href="http://roymacleanvba.files.wordpress.com/2010/11/invoice1.png"><img class="alignnone size-full wp-image-551" title="Invoice" src="http://roymacleanvba.files.wordpress.com/2010/11/invoice1.png?w=500&#038;h=295" alt="" width="500" height="295" /></a></p>
<p>The little green &#8216;f&#8217; icons represent the formulas, held as XML Processing Instructions. These are ignored in subsequent transformations (to final formats, such as PDF). You double-click an icon to edit the formula.</p>
<p>The first one (before the table) is today&#8217;s date: =today(). The ones in the Cost column are simple arithmetic: =($C2 * $D2), etc. Column and row headers can be displayed optionally:</p>
<p><a href="http://roymacleanvba.files.wordpress.com/2010/11/invoice2.png"><img class="alignnone size-full wp-image-552" title="Invoice2" src="http://roymacleanvba.files.wordpress.com/2010/11/invoice2.png?w=500&#038;h=138" alt="" width="500" height="138" /></a></p>
<p>The Product Description and Unit Price formulas are more interesting, since they are lookups in another document, containing the product catalog. Here&#8217;s the formula in B2:</p>
<p><a href="http://roymacleanvba.files.wordpress.com/2010/11/formula1.png"><img class="alignnone size-full wp-image-554" title="Formula1" src="http://roymacleanvba.files.wordpress.com/2010/11/formula1.png?w=500" alt=""   /></a></p>
<p>The first thing to notice is that we can have multi-line formulas, with &#8216;let&#8217; definitions preceding the actual formula. (The &#8220;&#8230;&#8221; is really a full file path &#8211; I&#8217;ve elided it for compactness). The id of the element with the product description is the product code appended with &#8220;_desc&#8221;. This is then retrieved from the product catalog by matching the id attribute (@id) with the constructed value ($id). (The back-quotes indicate &#8216;raw&#8217; XPath, rather than XXE formula language).</p>
<p>Here&#8217;s the Product catalog (not very extensive!):</p>
<p><a href="http://roymacleanvba.files.wordpress.com/2010/11/products.png"><img class="alignnone size-full wp-image-553" title="Products" src="http://roymacleanvba.files.wordpress.com/2010/11/products.png?w=500&#038;h=194" alt="" width="500" height="194" /></a></p>
<p>The formulas here are used not to calculate visible values, but to construct values for the id attribute. For example, in B2:</p>
<p><a href="http://roymacleanvba.files.wordpress.com/2010/11/formula2.png"><img class="alignnone size-full wp-image-555" title="Formula2" src="http://roymacleanvba.files.wordpress.com/2010/11/formula2.png?w=500" alt=""   /></a></p>
<p>Note the id attribute picked from the drop-down list. In Excel terms, this is rather like having a formula that constructs a Range name. It means that the ids for cells in column B and C always follow the product codes in column A. I think this is rather neat.</p>
<p>Back in the invoice, the Total Cost formula sums the values in the Cost column (E) &#8211; see the first scrrenshot. We could do this with a table/column reference, but an alternative is to tag the Cost cells with a common attribute value. In DITA, @outputclass allows a kind of informal specialization (we can&#8217;t use @id, as this must be unique within a document). Here, we can set @outputclass = &#8216;cost&#8217;. Now, the Total Cost formula sums all elements with this attribute value, wherever they are in the document:</p>
<blockquote><p>=sum(`//*[@outputclass='cost']`)</p></blockquote>
<p>That&#8217;s it, in terms of the documents. We can then generate formatted output, as we require.</p>
<p>The database aspect comes if the invoices are put into an XML database, such as XMLMind&#8217;s <a href="http://www.xmlmind.com/qizx/free_engine.html">Qizx (Free Engine edition)</a>. This provides indexing and querying, using the XQuery language. We can then calculate aggregated values, for example by customer and product. Here&#8217;s a simple query to calculate the total invoiced for a given product:</p>
<p><pre class="brush: plain;">
xquery version &quot;1.0&quot;;

let $prod := &quot;PR01&quot;    (:edit this:)

let $costs :=
 for $row in //strow
 let $cost := $row/stentry[@outputclass='cost']
 where $row/stentry[1]/text() = $prod
 return $cost
return ($prod, sum($costs))
</pre></p>
<p><em>strow </em>is a simple-table row, <em>stentry </em>is a cell. One could, of course, get a lot fancier, and produce proper date-based reports.</p>
<p>There&#8217;s an interesting contrast here with how we would do this in Excel. If each invoice is a separate Workbook, we would need to provide some collation mechanism for the data, to get it into a single source for pivot tables, etc. &#8211; either in a single workbook, or in Access. I think that where we have a large number of computationally relatively simple documents, the XML approach is quite attractive.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/roymacleanvba.wordpress.com/549/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/roymacleanvba.wordpress.com/549/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/roymacleanvba.wordpress.com/549/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/roymacleanvba.wordpress.com/549/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/roymacleanvba.wordpress.com/549/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/roymacleanvba.wordpress.com/549/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/roymacleanvba.wordpress.com/549/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/roymacleanvba.wordpress.com/549/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/roymacleanvba.wordpress.com/549/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/roymacleanvba.wordpress.com/549/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/roymacleanvba.wordpress.com/549/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/roymacleanvba.wordpress.com/549/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/roymacleanvba.wordpress.com/549/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/roymacleanvba.wordpress.com/549/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=549&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://roymacleanvba.wordpress.com/2010/11/08/spreadsheets-in-xml-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">roymacleanvba</media:title>
		</media:content>

		<media:content url="http://roymacleanvba.files.wordpress.com/2010/11/invoice1.png" medium="image">
			<media:title type="html">Invoice</media:title>
		</media:content>

		<media:content url="http://roymacleanvba.files.wordpress.com/2010/11/invoice2.png" medium="image">
			<media:title type="html">Invoice2</media:title>
		</media:content>

		<media:content url="http://roymacleanvba.files.wordpress.com/2010/11/formula1.png" medium="image">
			<media:title type="html">Formula1</media:title>
		</media:content>

		<media:content url="http://roymacleanvba.files.wordpress.com/2010/11/products.png" medium="image">
			<media:title type="html">Products</media:title>
		</media:content>

		<media:content url="http://roymacleanvba.files.wordpress.com/2010/11/formula2.png" medium="image">
			<media:title type="html">Formula2</media:title>
		</media:content>
	</item>
		<item>
		<title>Spreadsheets in XML</title>
		<link>http://roymacleanvba.wordpress.com/2010/11/01/spreadsheets-in-xml/</link>
		<comments>http://roymacleanvba.wordpress.com/2010/11/01/spreadsheets-in-xml/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 12:08:11 +0000</pubDate>
		<dc:creator>Roy MacLean</dc:creator>
				<category><![CDATA[Non-VBA]]></category>
		<category><![CDATA[DITA]]></category>
		<category><![CDATA[Formulas]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://roymacleanvba.wordpress.com/?p=542</guid>
		<description><![CDATA[In my work with DITA documentation, I use XMLMind&#8217;s XML Editor (XXE) &#8211; and very good it is too. The professional version comes with an Integrated Spreadsheet Engine, which I have just recently taken a look at. I think it&#8217;s rather interesting, particularly how the approach differs from Excel or similar traditional spreadhseets. We are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=542&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my work with <a href="http://roymacleanvba.wordpress.com/2009/08/25/digression-on-documentation-dita/">DITA documentation</a>, I use <a href="http://www.xmlmind.com/xmleditor/">XMLMind&#8217;s XML Editor (XXE)</a> &#8211; and very good it is too. The professional version comes with an Integrated Spreadsheet Engine, which I have just recently taken a look at. I think it&#8217;s rather interesting, particularly how the approach differs from Excel or similar traditional spreadhseets.</p>
<p>We are not talking here about Excel (2007+) using an XML-based file format. In this, the information is structured using elements that relate to spreadsheets &#8211; such as &lt;worksheet&gt; and &lt;row&gt; &#8211; not to the content domain (invoices, timesheets, product specifications, whatever). That means that the information is not in practice accessible to users (as opposed to tool developers).</p>
<p>What XXE is addressing is the insertion of computed element content into a &#8216;user level&#8217; XML document. Such a document could be in XHTML or DITA (XHTML is obviously a &#8216;final&#8217; format; DITA is a &#8216;source&#8217; format for conversion into various final formats, such as XHTML, PDF, CHM).</p>
<p>The idea is that the XML contains formulas as Processing Instructions. PIs are interpreted by the XXE application, but are ignored by XML processing tools and web browsers. A formula PI generates content (a result value) which is inserted between the PI and the end of the enclosing element. In practice, a formula will provide content for a lowest-level element such as a table entry, or a text phrase. Here is a simple-table entry:</p>
<blockquote><p>&lt;stentry&gt;<br />
&lt;?xxe-formula formula=&#8217;=($[+0,3] * $[+0,4])&#8217;?&gt;<br />
150<br />
&lt;/stentry&gt;</p></blockquote>
<p>This is in column 5 of a table, and is multiplying the values in columns 3 and 4, to produce the value 150. XXE provides a sugared syntax for references within a table, which is essentially the same as an Excel formula. So the above formula would actually be written as:</p>
<blockquote><p>=($C2 * $D2)</p></blockquote>
<p>with the relative addressing of the rows allowing the formula to be copy-pasted in subsequent rows.</p>
<p>In XML, any element can have an <em>id </em>attribute. For a table element, this allows us to reference a value in a table from outside (from ordinary text elements). For a leaf element, this allows us to reference a value by name. Suppose that <em>invoice_table</em> contains details of an invoice, and cell D7 contains the <em>tax</em>. We could have a formula:</p>
<blockquote><p>=invoice_table!$D$7</p></blockquote>
<p>or, better:</p>
<blockquote><p>=$(tax)</p></blockquote>
<p>There are, as you would expect, a reasonable number of built-in functions, in the usual categories.</p>
<p>An interesting twist is that a formula can set not just element content, but alternatively an element attribute. The most obvious use of this is to generate id attributes. For example, suppose that I have a table with Product Codes in column A, and Unit Prices in column B. Then, in the B2 cell, I can have this formula setting the id attribute:</p>
<blockquote><p>=($A2 &amp; &#8220;_unitprice&#8221;)</p></blockquote>
<p>(and similarly for the rest of column B). Now, if I want to look up a unit price, I simply construct the id from the product code and the suffix, and access the element directly by id &#8211; no need for a VLOOKUP function.</p>
<p>So far, the main difference from Excel is that we are not restricted to using  tabular structures (worksheets, in Excel). We can have values and formulas anywhere in a document structure. For erxample, I could drop a calculated value into an ordinary free-text paragraph, and pick up that value elsewhere in the document.</p>
<p>However, the really different aspect is that the formulas are based on the XPath 1.0 language &#8211; the Excel-like syntax is just cosmetic. XPath is a pattern-based query language that treats XML documents as trees of nodes-with-attributes. Here&#8217;s an <a href="http://www.zvon.org/xxl/XPathTutorial/Output/example1.html">example-based tutorial</a>. This means that a formula can operate on a set of nodes (returned from an XPath expression), without knowing how many there are or where they are in a document.</p>
<p>We can tag values (wherever they are) using an attribute. In DITA, we could use @outputclass (not @id, as this must be unique). For example, I could tag various elements (possibly table cells, possibly not) with @outputclass = &#8216;cost&#8217;, and then sum these using the formula:</p>
<blockquote><p>=sum(`//*[@outputclass='cost']`)</p></blockquote>
<p>The backquotes encapsulate an XPath expression (as opposed to the XXE formula language). &#8216;//*&#8217; means &#8220;any element anywhere in the document&#8221; (which we then filter by the outputclass attribute). Furthermore, XPath can access not only the current document, but also other documents (as individual documents, not as a document collection &#8211; a notion supported by XPath 2.0/XQuery).</p>
<p>I&#8217;ll discuss an example of all this in the next post.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/roymacleanvba.wordpress.com/542/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/roymacleanvba.wordpress.com/542/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/roymacleanvba.wordpress.com/542/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/roymacleanvba.wordpress.com/542/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/roymacleanvba.wordpress.com/542/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/roymacleanvba.wordpress.com/542/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/roymacleanvba.wordpress.com/542/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/roymacleanvba.wordpress.com/542/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/roymacleanvba.wordpress.com/542/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/roymacleanvba.wordpress.com/542/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/roymacleanvba.wordpress.com/542/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/roymacleanvba.wordpress.com/542/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/roymacleanvba.wordpress.com/542/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/roymacleanvba.wordpress.com/542/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=542&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://roymacleanvba.wordpress.com/2010/11/01/spreadsheets-in-xml/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">roymacleanvba</media:title>
		</media:content>
	</item>
		<item>
		<title>Code Quality</title>
		<link>http://roymacleanvba.wordpress.com/2010/10/18/code-quality/</link>
		<comments>http://roymacleanvba.wordpress.com/2010/10/18/code-quality/#comments</comments>
		<pubDate>Mon, 18 Oct 2010 16:54:38 +0000</pubDate>
		<dc:creator>Roy MacLean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[teaching]]></category>

		<guid isPermaLink="false">http://roymacleanvba.wordpress.com/?p=534</guid>
		<description><![CDATA[An interesting essay on Code Quality by Hew Wolff, over at the Pragmatic Programmers, in their online magazine. The basic thesis is that &#8216;Good Code Tells the Truth&#8217; (that&#8217;s the title). It resonated with me because a week or two back I was looking at an Access/VBA application (not one of mine!). The code in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=534&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>An interesting <a href="http://www.pragprog.com/magazines/2010-10/good-code-tells-the-truth">essay on Code Quality</a> by Hew Wolff, over at the Pragmatic Programmers, in their online magazine. The basic thesis is that &#8216;Good Code Tells the Truth&#8217; (that&#8217;s the title). It resonated with me because a week or two back I was looking at an Access/VBA application (not one of mine!). The code in this application was, if I might be frank, dire:</p>
<ul>
<li>no indentation in a lot of procedures</li>
<li>no splitting of long SQL strings over multiple lines (when I did reformat one, it ran to 8 lines)</li>
<li>no useful comments at either module/form or procedure level</li>
<li>form controls not renamed (one form had buttons called Command27, Command28, Command66, Command139 &#8211; see what I mean?)</li>
<li>obscure variable names &#8211; for example, in one procedure, U3, D3, d4, SN3, FN3</li>
<li>using 0 and -1 for False and True (why?)</li>
<li>copy-paste-and-tweak repetition (e.g. to re-initialize a form).</li>
</ul>
<p>The <em>piece de resistance</em> was a SELECT-INTO query that created a column using this expression:</p>
<blockquote><p>[id]-[id]-1</p></blockquote>
<p>So, arithmetic on Ids? As far as I can tell, this converts an Id value into -1 (presumably treated as True), but leaves Null values as Null, since arithmetic expressions involving Nulls equal Null. Is this a common Access programming technique? Even if it is, couldn&#8217;t it be wrapped in a function called something like <em>NonNullToTrue </em>(although this could not have argument or result types more specific than Variant).</p>
<p>This might (or might not) be a clever trick, but not considering the possibility of other people finding it confusing indicates of a poor approach to programming. What the essay mentioned earlier is saying, and what I&#8217;m agreeing with here, is that software development is as much about <em>communication of a solution</em> as it is about that solution just working.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/roymacleanvba.wordpress.com/534/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/roymacleanvba.wordpress.com/534/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/roymacleanvba.wordpress.com/534/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/roymacleanvba.wordpress.com/534/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/roymacleanvba.wordpress.com/534/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/roymacleanvba.wordpress.com/534/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/roymacleanvba.wordpress.com/534/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/roymacleanvba.wordpress.com/534/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/roymacleanvba.wordpress.com/534/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/roymacleanvba.wordpress.com/534/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/roymacleanvba.wordpress.com/534/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/roymacleanvba.wordpress.com/534/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/roymacleanvba.wordpress.com/534/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/roymacleanvba.wordpress.com/534/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=roymacleanvba.wordpress.com&amp;blog=6292206&amp;post=534&amp;subd=roymacleanvba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://roymacleanvba.wordpress.com/2010/10/18/code-quality/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">roymacleanvba</media:title>
		</media:content>
	</item>
	</channel>
</rss>
