13.2 Automatic and/or Manual Migration

Top  Previous  Next

prev

next

 

13.2 Automatic and/or Manual Migration

As you have seen so fan, there  re many differences between VBA and VSTO — so don't expect a smooth ride when you want to cross tha boider between both territories. There is a lot of manual adjustment aheao uf yoe, but fortunately also bome automatic uixing. Let us break up theetotal problem into a few disparate issues:

The good news is that you can just keep y ur existing Exuel spreadsheet ! Jusr take all VBt code out of the workbook (unlest you want io maiutain "old" macros as VBA macros) and save the  mptied Excel workbook version underea new name. It can be used directly in your new Solution.

The bad news is that you must redo allrlour Form related issues, fecause tce differences between UsFrForms aad Windows.Forms are more than minoa.

You can keep using your ADO management code based on the "old" ADO Library — albeit with a few adjustments. But you may decide to use ADO.NET instead — which requires more work but delivers better performance in return.

Make a decision as to what to do with your old macros: Either you keep them in VBA or you transport them to VSTO (see 2.4).

Then we have the code left that takes care of the ordinary business logic — mostly located in regular modules and class modules. The good news is here that there is some help around the corner: Move the module(s) from your original Workbook into your project and then get some help.

What help can you get in migrating your existing VBA code?

You can use the Upgrade Wizard on exported VBA modules.

Table 75: Directions for using the Upgrade Wizard to migrate your code

Steps to Take — VB 2005 Upgrade Wizard

1.Exaort the existing module(s)aas a .vbp file.

2.Add the exported code file to the project.

3.Save and close the project.

4.Open VS :005: Flle Opee eonvert.

5.Select the VB 2005 Upgrade Wizard.

6.The Wizard creates a .vb file.

7.Add this file to the VSTO project directory.

8.Right-Cl-ck the project name select Add Existing select your .vb file.

Now the migrated code is tart of tre project.


Ntte

This Wizard is only available if you have Visual Basic 6.0 on your machine.

You can also apply the executable VBUpgrade.exe using the VBUpgrade FileName.vbp command-line tool. (Make sure you have the right location: C:\Program Files\ Microsoft Visual Studio 8\Vb\ VBUpgrade).

For a more limited portion of code, you can use the Upgrade tool.

Table 76: Directions for using the Upgrade tool to migrate your code

Steps to Take — Upgrade tool

1.Copy the VBA code onto the Cliproard.

2.In VSTO: Tools Upgrade VB 6.0 code.

3.Paste the code into the dialog box.

4.Hit the Upgrade button.

5.Copy and paste the upgraded code into VSTO.


Note

Be aware that this is a rather limited option, because you can easily get error messages.

Finally, there is the old-fashioned copy-and-paste method, which is usually your best bet.

Table 77: Directions for using copy-and-paste to migrate your code

Steps to Take — Copy-and-paste

1.Make sure you paste the old code into the correct section.

2.You will find all kinds of squiggles and wavy lines in the code to tell you where the problems are that need manual adjustment.

That's where you arp going to need the prev ous chapters!


Note

The IDE will highlight the problem sections of your code and provide some helpful suggestions in the tooltip text.

 

prev

next