VBA: CallByName and InvokeHook - vba

'In VBA one disadvantage of calling a class procedure with CallByName ist that when an custom error was raised in the called object procedure, the caller always gets error 440 regardless of the original error number being raised.
Microsoft gives a workaround in this article http://support.microsoft.com/kb/194418/en-us.
It suggests instead of CallByName the use of InvokeHook. Therefore the library "TypeLib Information" (TLBINF32.DLL) must be added as a reference.
My question is: is this library available by default on every Windows PC, where only MS Office is installed (no Visual Studio etc.)?
Thanks in advance for your answers

Related

vba compile error function or interface marked as restricted VBA Error when interfacing from Access to .NET com dll

I have a com dll created in VB.NET that has been working for a number of years. The dll takes information from MS Access and creates orders on eBay using their Soap api. All of a sudden I started getting the error message "vba compile error function or interface marked as restricted, or the function uses an automation type not supported in Visual Basic" when I compile the Access application. The error is on a line where a property of type decimal in the dll is updated with data of type decimal from an DAO recordset. This part of the code has been stable for quite a while so I am at a loss as to why all of a sudden this error starts. Any suggestions would be appreciated.
For future reference. It appears that MS Access type decimal is not equivalent to VB.NET type decimal. MS Access sees VB.NET double as equivalent to its type decimal. Once I converted my property to a double data type the compile error went away.

Build Error in VB.NET program when MS Office XP is upgraded to MS Office 2007

I have a VB.NET 2010 program that works perfectly with MS Office XP. Because of security concerns attributed to Office XP, I recently upgraded to MS Office 2007. I made no changes to the VB program.
A single Build Error, Type Excel.Global is not defined. is preventing the program from running. The ErrorList points to the UpgradeSupport module as the location of the error.
The entire UpgradeSupport module is as follows:
Module UpgradeSupport
Friend DAODBEngine_definst As New DAO.DBEngine
Friend ExcelGlobal_definst As New Excel.[Global]
End Module
The instance of Excel.[Global] above is the only visible instance of it in the entire program, and there are no instances of Excel.Global at all, anywhere. The variable name, Excel.Global (or Excel.[Global]) suggests a structure. Moreover, I believe Global (or [Global]) is a property, not a type, and I believe Excel.Global and Excel.[Global] are not equivalent expressions. I can successfully define structure Excel.[Global] as follows:
Public Structure Excel
Shared Property [Global] As Object
End Structure
Note: The above will not define successfully without the square brackets around Global, which supports my assertion that the two expressions are not equivalent. I question whether any instance of Type Excel.Global exists in the program. Nevertheless, the Build Error continues to prevent the program from running. How can I eliminate the Build Error?

DLL function calling in Excel Macro

enter image description hereWhen I execut the Code when the function of DLL calls it give error 429 "Active X component did not Create Object"...
Here i depicted the VBA code which i use.
I also include the libraries..
Sample.tlb
Microsoft Active X 6.0 Object Library
'Microsoft Office 14.0 Access Database Engine Object'
I run this code in MS Office 2010 64 bit and 64 bit Operating System.
This might help. It looks like your Activex component must yet be registered.

Spurious "User-defined type not defined" error in Microsoft Word VBA

I have a Microsoft Word template with some code and some references, that has been working fine for months but has just started throwing up a spurious "User-defined type not defined" error whenever I open it or try to compile it.
I know it's a spurious error because I haven't made any significant changes to the code. In fact, I've rolled the code back to the last deployed version (which I know works fine) and I still get the error. I've also commented out all the code in the template and I still get the error. I've also removed and re-added all references (same error), and removed all the references and added them back, one by one, until the resultant compile errors are resolved, at which point I'm left with the spurious "User-defined type not defined" error. (I'm going to call this a UDTND error, from now, to avoid driving you all mad.) I think the error started popping up after I rebooted my PC. It only happens with this template, but I don't see how it can be anything to do with this template.
Interestingly, the error is subtly different from a genuine UDTND error in the following ways:
No code is highlighted when the error is displayed.
The dialog is titled "Microsoft Visual Basic", and contains the error message but, unlike a real UDTND error, doesn't contain the text "Compile error:";
It happens when the template is opened, not just when it's compiled (at least, I think that's different from a normal error).
I've tried Googling it but I just get a bazillion results from novice developers asking why they get this error, with responses telling them that they either need to declare the missing type, correct the spelling of the offending variable type, or add a reference to a missing library. I've been banging my head against my screen all afternoon, and that's helped about as much as all the other things I've tried (i.e. not at all). I have a feeling that this is something to do with a messed-up reference, but afaict they're all fine, and I've removed and re-added them, which I would expect to resolve that sort of problem.
Any ideas...?
Your trouble-shooting on References is sound. Once upon a time (and I don't recall the precise error) I was at the same point, and the reference ordering was the key. When you're designating References, you'll notice a "Priority" adjustment feature. Experiment with that and you may solve this.
I have had "User-defined type not defined" problem on several occasions when compiling Microsoft Visual Basic 6 (MSVB6) code that was compiling without a problem earlier. It seems to happen after I have had a long coding session without rebooting the computer. As you can guess, I have been using Microsoft operating systems. I currently am using Windows XP. Rebooting the computer usually fixes the problem as it so often does on Microsoft operating systems.
I have read that fully qualifying declarations also can help, e.g., "Dim oBar as Foo.Bar" instead of "Dim oBar as Bar". I have not tried this approach however.
I had a very similar problem.
My problem appeared (I think) just after I made a Search and Replace that I canceled (Ctrl+Z). There was not highligting of the problem, only the ""User-defined type not defined" error message when I compiled.
I tried:
1) restarting computer
2) changing reference ordering
3) removing functions/procedures, modules one at a time.
Didn't work. My project was written in Excel VBA and here was the solution I found.
THE SOLUTION:
I opened a new Excel file and opened the Visual Basic Editor. I then copied all Forms, Modules, and Class Modules one by one into the new file. I then Copied the Control Objects (3 Commandbuttons) from the old sheet into the new one. Now the new file was identical to the old project - only the ""User-defined type not defined" had gone and problem was solved.
Yea references would be the first step in troubleshooting this problem as already stated, but failing that id start commenting out the code in any event procedures running at start up (my experience is only with Access VBA though)
I had the same problem with Excel 2013.
It started when I did a search and replace on the name of a Custom Class.
I changed the name of the Class after I did the search and replace on all references to it and the spurious error started immediately after that.
I reverted to an earlier version ad confirmed that the problem was not there and then did the same search and replace and re-name and got the exact same behaviour again.
The Custom Class that I changed the name of only had one consumer and it was also a custom class.
I exported, removed and re-loaded the sole consumer class and the problem was fixed.
Check out this link for a Microsoft bug that might be related.
TLDR:
The reference to a package/addin/whatever probably needs to be re-referenced. Check Tools -> References in the Menu.
Also it appears that if you install Microsoft Security Advisory 960715, that certain controls are killed. There are fixes which may or may not work for you. A good article is on this blog:
VSOD Blog

Problem with Statement Completion in Visual Studio 2008 SP1

After installing SP1 of Visual Studio 2008, code completion shows all types when an object member shows the parameter list. Before SP1, parameter list would only show related types.
Take a look at this image for an example: http://img25.imageshack.us/img25/3484/vs2008sp1intellisense.png
Has any one else had this problem? Solutions?
This happens on a Windows 7 and Windows XP machines I have, all services packs installed.
Thanks
Javier Soques
This isn't related to the service pack. I've verified the same behavior on an RTM version of Visual Studio 2008.
What you're seeing here is an issue of overload resolution. In the particular example you are using the MessageBox.Show method which has 21 overloads.
With no arguments and just MessageBox.Show( typed in the editor it's ambiguous as to which version you will be calling. So instead of showing specific types, it will show the completion list for all expression types.
Once the overload is not ambiguous it will show the specific type list. For instance if you type
MessageBox.Show("foo","bar",
It will show only the button enumeration completion.