Office Macro Errors and Compile errors
I'll be creating an index once I reach my 25 errors per page limits.
Here's the process. While I work with MS Office creating Macro's I'll publish the errors I find as I create them with the MS Macro tools.
When you're using Tools to create your work you're allowing another programmer to think for you. At times this makes the work easier because that programmer most likely knows allot more than you do about MS Office.
But, when that program tool tosses an error like "Compile Error:" with a description of "Syntax error" and you just added a custom theme where do you start to debug?
Let's take baby steps and learn to read.
Yes, VB programing is all about "Left to Right" and "Top to Bottom" even when you create functions and sub routines you are still reading the same. Don't skip a single line.
Next tip I can offer is to know what " and ' are used for. Then watch for your common typo's. I'm at about 99.999% (exaggerating a bit) for every million lines of code. That basically shows I made 2 typos in the year 2012 when writing code. That isn't saying I didn't make typos in other areas it just means my coding typed accurately which shouldn't be confused with neat or clean code.
Ok, let's get to the first one I saw today using the Record Macro function in Office 2010.
Office 2010 Pro
Compile Error = Syntax Error
I created an Excel sheet with custom colors and selected a Theme.
When I selected the them my link was added as shown below
ActiveWorkbook.Theme.ThemeColorScheme.Load ( _
"C:\Program Files\Microsoft Office\Document Themes 14\Theme Colors\Aspect.xml")
But the first entry ActiveWorkbook.Theme.ThemeColorScheme.Load() was not updated, removed, deleted or changed. The Macro used the template and added the them thus...
Syntax Error = ActiveWorkbook.Theme.ThemeColorScheme.Load() Why?
Look () is blank.
Do this add "" inside the ().
Now run it and you should see a run-time error.
That's the line causing you the Syntax error because it is a sub routine that requires some parameter and that parameter is missing.
Now, if you know for a fact that is the cause then delete the line.
But, if you are still running your debug just comment that line out by adding a ' in the first space of that line.
If you see _ at the end that's telling you the line wraps which is a coders way of keep neat code and readable code.
Try it, add a duplicate routine and omit the required parameters.
Last tip for this error: Never post in any VB forum that you have a Syntax Error without the actual code. If you know the area of the error you can paste that if you don't you need to paste the full script.
If you don't trust your code to the internet and public forums you can save your code as a text file and email it to another programmer like myself for review. I'll be debugging Macro's during a upgrade soon which should allow me to brush up on things and identify issues quickly.
Have a great error free day!
PS: Virtual desktop debugging requires a VPN connection to my VDI. It works with any IPSec if I can remember the Shared Key that is.
It's called, Collaboration amongst programmers which is rough since we don't trust programmers.... much.