<?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>Soundside Software &#187; VBA</title>
	<atom:link href="http://www.soundsidesoftware.com/category/microsoft-office/vba-microsoft-office/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.soundsidesoftware.com</link>
	<description>...precision software, by design</description>
	<lastBuildDate>Sat, 24 Dec 2011 17:34:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>The Feasibility of Converting Office VBA Applications to VB6</title>
		<link>http://www.soundsidesoftware.com/the-feasibility-of-converting-office-vba-applications-to-vb6/</link>
		<comments>http://www.soundsidesoftware.com/the-feasibility-of-converting-office-vba-applications-to-vb6/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 15:40:09 +0000</pubDate>
		<dc:creator>David Horowitz</dc:creator>
				<category><![CDATA[Microsoft Office]]></category>
		<category><![CDATA[VB6]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://www.soundsidesoftware.com/?p=167</guid>
		<description><![CDATA[The first thing one should address in an article about converting Office VBA applications to VB6 is &#8220;WHY?&#8221; Why would someone bother in the year 2011 to convert one decade-old technology to another decade-old technology? The answer is this: many businesses are still using these technologies. Especially large firms find it takes many years to <a href='http://www.soundsidesoftware.com/the-feasibility-of-converting-office-vba-applications-to-vb6/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>The first thing one should address in an article about converting Office VBA applications to VB6 is &#8220;WHY?&#8221;
</p>
<p>Why would someone bother in the year 2011 to convert one decade-old technology to another decade-old technology?
</p>
<p>The answer is this: many businesses are still using these technologies. Especially large firms find it takes many years to switch to the latest and greatest.
</p>
<p>Some of my clients still use Office 2003 or even Office 2000.
</p>
<p>And I&#8217;m not talking only about small companies who perhaps don&#8217;t know any better or who are on tight budgets. I&#8217;m talking about large multinationals, the largest companies in the world.
</p>
<p>The next question is: why convert from Office VBA to VB6?
</p>
<p>The answers:
</p>
<ul>
<li>To create a free-standing application executable, one which doesn&#8217;t use a Word document or template directly to house the code. Granted, there are other ways to do this, but using VB6 may be one of the simplest.
</li>
<li>To take advantage of the speed advantage by using a compiled language like VB6 versus a semi-compiled/interpreted language like Office VBA.
</li>
<li>To have your code run in a more stable environment – VB6 versus Office VBA.
</li>
</ul>
<p>While we won&#8217;t go into a detailed technical how-to here, we will address the feasibility.
</p>
<p>The answer is: yes, it is feasible to convert Office VBA applications to VB6 applications.
</p>
<p>The language syntaxes are virtually identical.
</p>
<p>Here are a few pointers:
</p>
<ul>
<li>You must physically move the code. There are easy ways to do this.
</li>
<li>You must set proper References to the Office libraries that are usually set by default within the Office VBA environment.
</li>
<li>You must account for the differences between the Application object in Office VBA and the App object in VB6. They have little in common.
</li>
<li>Generally, you may find it best to use full object qualification in your code. For example, I routinely use Word.Document as an object type in my Word VBA code rather than simply Document. This does tend to make things a bit easier when converting to VB6. If you do this, you can be sure you&#8217;re referring to the correct object type. The same object type may exist in different libraries. I also use Word.Application rather than simply Application.
</li>
<li>With a bit of diligence and a cool head, you can successfully convert your Office VBA applications to VB6 applications.
</li>
</ul>
<p>Please feel free to <a href="/contact" title="Soundside Software Contact Page">contact us</a> here at Soundside more information. And happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.soundsidesoftware.com/the-feasibility-of-converting-office-vba-applications-to-vb6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting the Range of the top of the next page in Word VBA</title>
		<link>http://www.soundsidesoftware.com/getting-the-range-of-the-top-of-the-next-page-in-word-vba/</link>
		<comments>http://www.soundsidesoftware.com/getting-the-range-of-the-top-of-the-next-page-in-word-vba/#comments</comments>
		<pubDate>Thu, 04 Nov 2010 23:57:06 +0000</pubDate>
		<dc:creator>David Horowitz</dc:creator>
				<category><![CDATA[Microsoft Office]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[range]]></category>
		<category><![CDATA[top of next page]]></category>
		<category><![CDATA[Word VBA]]></category>

		<guid isPermaLink="false">http://www.soundsidesoftware.com/getting-the-range-of-the-top-of-the-next-page-in-word-vba/</guid>
		<description><![CDATA[This function conveniently returns a collapsed Range that contains the top of the next page in a Word document.]]></description>
			<content:encoded><![CDATA[<p>I needed a function that would conveniently return me a Range that contained the top of the next page in a Word document.</p>
<p>The following does the trick:</p>
<pre>Function TopOfNextPage(rng As Word.Range) As Word.Range
    Set TopOfNextPage = rng.Duplicate.GoTo(What:=wdGoToPage, Which:=wdGoToNext)
End Function </pre>
<p>Notice it does not disturb the original Range. It accomplishes this by use of the Range.Duplicate function, which I find very handy sometimes when I don&#8217;t want to disturb my original Range.</p>
<p>Notice the returned Range is collapsed to the top of the page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.soundsidesoftware.com/getting-the-range-of-the-top-of-the-next-page-in-word-vba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IsLastPage Function in Word VBA</title>
		<link>http://www.soundsidesoftware.com/islastpage-function-in-word-vba/</link>
		<comments>http://www.soundsidesoftware.com/islastpage-function-in-word-vba/#comments</comments>
		<pubDate>Thu, 04 Nov 2010 23:52:52 +0000</pubDate>
		<dc:creator>David Horowitz</dc:creator>
				<category><![CDATA[Microsoft Office]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[last page]]></category>
		<category><![CDATA[Word VBA]]></category>

		<guid isPermaLink="false">http://www.soundsidesoftware.com/islastpage-function-in-word-vba/</guid>
		<description><![CDATA[Here’s a handy little function that tells you if the end of a Range in Word VBA lies on the last page of the document.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a handy little function that tells you if the end of a Range in Word VBA lies on the last page of the document:
<pre>Function IsLastPage(rng As Word.Range) As Boolean
     IsLastPage = CBool(rng.Information(wdActiveEndPageNumber) = rng.Information(wdNumberOfPagesInDocument))
End Function </pre>
<p>The Range.Information function is very useful. Check it out!</p>
<p>We hope it comes in handy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.soundsidesoftware.com/islastpage-function-in-word-vba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>InsertFieldAfter Function in Word VBA</title>
		<link>http://www.soundsidesoftware.com/insertfieldafter-function-in-word-vba/</link>
		<comments>http://www.soundsidesoftware.com/insertfieldafter-function-in-word-vba/#comments</comments>
		<pubDate>Thu, 04 Nov 2010 23:48:22 +0000</pubDate>
		<dc:creator>David Horowitz</dc:creator>
				<category><![CDATA[Microsoft Office]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[extend range]]></category>
		<category><![CDATA[insert field]]></category>
		<category><![CDATA[Word VBA]]></category>

		<guid isPermaLink="false">http://www.soundsidesoftware.com/insertfieldafter-function-in-word-vba/</guid>
		<description><![CDATA[Here's a ready-to-use function in Word VBA that adds a Field to a Range’s Fields collection and automatically extend the Range to include the added field.]]></description>
			<content:encoded><![CDATA[<p>I wanted a function in Word VBA that would add a Field to a Range’s Fields collection and automatically extend the Range to include the added field.</p>
<p>This mimics the behavior of the Range.InsertAfter function and similar functions.</p>
<p>It allows you to keep adding text, fields, and other items to a Word document sequentially.</p>
<p>The function I created is called InsertFieldAfter. Its parameters mimic the parameters to the Fields.Add function.</p>
<p>The Range you pass in is extended to include the newly added Field. The new Range is also returned as the function return value for convenience.</p>
<p>The text of the function and related support functions is below, followed by an example of how to use the function.</p>
<pre>' Expand the Range to include the added field and return it. Public Function InsertFieldAfter( _
             ByRef Range As Word.Range, _
             ByVal FieldType As WdFieldType, _
             ByVal Text As String, _
             Optional ByVal PreserveFormatting As Boolean = False _
         ) As Word.Range
     On Error GoTo handler
     Dim StartPos As Long, EndPos As Long
     StartPos = Range.Start
     Range.Collapse Direction:=wdCollapseEnd
     EndPos = Range.Fields.Add( _
             Range:=Range, _
             Type:=FieldType, _
             Text:=Text, _
             PreserveFormatting:=PreserveFormatting) _
         .Result.End + 1
     Range.SetRange StartPos, EndPos
     Set InsertFieldAfter = Range
     Exit Function
handler:
     ' handle any run-time error here
End Function </pre>
<p>Here&#8217;s a code snippet showing an example of its use:</p>
<pre>With myRange
     .InsertAfter "Here is a field: "
     InsertFieldAfter Range:=myRange, FieldType:=wdFieldEmpty, Text:="REF Field1"
     .InsertAfter vbCrLf &#038; "Here is another field: "
     InsertFieldAfter Range:=myRange, FieldType:=wdFieldEmpty, Text:="REF Field2"
     .InsertAfter vbCrLf
End With </pre>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.soundsidesoftware.com/insertfieldafter-function-in-word-vba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic UserForms in VBA</title>
		<link>http://www.soundsidesoftware.com/dynamic-userforms-in-vba/</link>
		<comments>http://www.soundsidesoftware.com/dynamic-userforms-in-vba/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 06:11:07 +0000</pubDate>
		<dc:creator>David Horowitz</dc:creator>
				<category><![CDATA[Microsoft Office]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[Dynamic UserForms]]></category>

		<guid isPermaLink="false">http://www.soundsidesoftware.com/?p=113</guid>
		<description><![CDATA[Learn how to create custom dialog boxes in Office apps that change their appearance depending on the data selected.]]></description>
			<content:encoded><![CDATA[<h1>Dynamic UserForms in VBA</h1>
<h3><a href="http://pubs.logicalexpressions.com/Pub0009/LPMFrame.asp?CMD=AuthorDetail&amp;ID=26" target="_blank">by David Horowitz</a></h3>
<div>
<p>Did you know that you can add and remove controls from a UserForm (also known as custom dialog boxes) at run-time? This means that you can change your UserForms based on certain conditions that exist during the operation of your VBA project—you’re not limited to the design of the UserForm that you created in the VBE designer!</p>
<p>To illustrate the technique, we’ll create a Word VBA Template which will prompt the user for the number of cars they own. (It allows for up to 20—hopefully that will be enough for most of us!) It will then display the correct number of textboxes to allow the user to enter the make of each car. When the user is done, the list of cars will be added to the document.</p>
<p>The key thing here we want to illustrate is the part where the dialog box will actually change to display the correct number of textboxes (with accompanying labels).</p>
<p>The primary method that accomplishes this task is <strong>Form.Controls.Add</strong>. (You can look it up in VBA Help.) Its syntax is like this:</p>
<pre>Set ctl = Me.Controls.Add(ControlClass, Name, Visible)</pre>
<p>For our purposes, <strong>ControlClass</strong> can have one of the following values:</p>
<pre>"Forms.CheckBox.1"
"Forms.ComboBox.1"
"Forms.CommandButton.1"
"Forms.Frame.1"
"Forms.Image.1"
"Forms.Label.1"
"Forms.ListBox.1"
"Forms.MultiPage.1"
"Forms.OptionButton.1"
"Forms.ScrollBar.1"
"Forms.SpinButton.1"
"Forms.TabStrip.1"
"Forms.TextBox.1"
"Forms.ToggleButton.1"</pre>
<p>These are <em>text</em> strings, so you must enclose them in quotes.</p>
<p>You can optionally specify the name of the new control using the <strong>Name</strong> parameter, for example, &#8220;TextBox7”, &#8220;txtFirstName”, &#8220;lblPrompt”, or &#8220;chkChicago”, whatever’s appropriate for your use.</p>
<p>Finally, you can choose to make the new control invisible by specifying <strong>False</strong> for the <strong>Visible</strong> parameter. The default is for Visible to be True.</p>
<p>So, for example, let’s say you would like to add a new label to your form. The form is named frmMyForm, and the new label should have the name &#8220;lblPrompt”. The method call would look like:</p>
<pre>Dim myLabel as Label
Set myLabel = frmMyForm.Controls.Add _
    ("Forms.Label.1", "lblPrompt")</pre>
<p>Don’t get confused about myLabel and lblPrompt. myLabel is an Object variable in VBA which is now set to refer to the control on the form by the name of &#8220;lblPrompt”.</p>
<p>Once you add a control to a form, you will certainly need to set some properties on the control, at least things like <em>Top</em>, <em>Left</em>, <em>Width</em> and <em>Height</em>. You can do this right after creation if you want, using, in our example, myLabel:</p>
<pre>With myLabel
    .Left = 10
    .Top = 10
    .Width = 30
    .Caption = "Enter your name:"
End With</pre>
<p>We’ve let the Height property default to whatever VBA sets for it initially.</p>
<p>Now later on in your code, if you want to refer to the newly added control, but you no longer have the myLabel reference, you can either use:</p>
<pre>frmMyForm.Controls("lblPrompt”)</pre>
<p>or</p>
<pre>frmMyForm!lblPrompt</pre>
<p>You <strong>cannot</strong> use the other syntax to refer to a control:</p>
<pre>frmMyform.lblPrompt</pre>
<p>when the control has been created dynamically using Controls.Add.</p>
<p>The example which accompanies this article, <strong><em>Dynamic UserForms Demo.dot</em></strong>, is a Word template which illustrates the techniques we’ve just describes in greater detail and in actual usage. You can download a copy of this template demo by clicking: <a href="http://www.mousetrax.com/pub/DynamicUserFormsDemo.zip">HERE</a>.</p>
<p>When you open this template, the <strong>Document_New</strong> method will call <strong>ShowCarsDialog</strong>, which will call the <strong>frmCars.Show</strong> method. frmCars has a label (lblNumCars) and textbox (txtNumCars), which prompt you to enter the number of cars you have. When you click on the <strong>Show Cars</strong> button (cmdShowCars), you will see a number of labels and textboxes equal to the number of cars you entered, allowing you to enter a make for each car. Then, when you click the Done button (cmdDone), all the car makes you entered will be inserted into the document and the dialog form (frmCars) will be unloaded.</p>
<p>If you want to change the number of cars again before you press Done, you can do that and when you click on Show Cars, the number of car labels and textboxes will change again to accommodate. So you can Add and Remove cars from the list before you click Done.</p>
<p>When you look at the code, you will see that each car make has a label and a textbox called <strong>lblCarN</strong> and <strong>txtCarN</strong>, where <strong>N</strong> is the <strong>number</strong> of the car. Each label is added to the form using this line of code:</p>
<pre>Set theLabel = Me.Controls.Add _
    ("Forms.Label.1", "lblCar" &amp; CurrentNumberOfCars)</pre>
<p>Each textbox is added to the form using this line of code:</p>
<pre>Set theTextBox = Me.Controls.Add _
    ("Forms.TextBox.1", "txtCar" &amp; CurrentNumberOfCars)</pre>
<p>After creating each control, we set a number of properties on it. We set each label’s caption using this line of code:</p>
<pre>theLabel.Caption = "Car #" &amp; CurrentNumberOfCars &amp; ":"</pre>
<p>You can see we even set the <strong>Accelerator</strong> property on each label to the number of the car using this line of code:</p>
<pre>theLabel.Accelerator = CurrentNumberOfCars</pre>
<p>If you tell the dialog box to remove some cars, the following lines of code are used:</p>
<pre>Me.Controls.Remove "lblCar" &amp; CurrentNumberOfCars
Me.Controls.Remove "txtCar" &amp; CurrentNumberOfCars</pre>
<p>In this article, we’ve learned how to use <strong>Form.Controls.Add</strong> to add controls to a form’s Controls collection at run-time. We then set properties on the control to make it look and function the way we want. We also learned how to dynamically remove a control from a form’s Controls collection using <strong>Form.Controls.Remove</strong>.</p>
<p>Now you can experiment with adding and removing controls to your forms whenever you need them. You will find many uses for this technique once you’ve learned how to do it.</p>
<hr />This article originally appeared in <a href="http://pubs.logicalexpressions.com/Pub0009/LPMIssue.asp?ISI=18" target="_blank">Vol 3, Issue 2</a> of TechTrax.</p>
<p>Need further help getting your VBA code working right? <a title="Contact us" href="/contact/" target="_self">Contact us</a> or check out TechTrax&#8217;s free VBA support groups. See these links for details: <a href="http://groups.yahoo.com/group/Word_VBA/" target="_blank">http://groups.yahoo.com/group/Word_VBA/</a> and/or <a href="http://groups.yahoo.com/group/ExcelVBA/" target="_blank">http://groups.yahoo.com/group/ExcelVBA/</a>.</p>
<p style="text-align: center;"><a href="http://www.mousetrax.com/techtrax_rating.asp?ID=259" target="_blank"><img src="http://pubs.logicalexpressions.com/Pub0009/userimages/ai1500.gif" border="0" alt="" width="187" height="30" /></a> </p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.soundsidesoftware.com/dynamic-userforms-in-vba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

