Hidden reefs of VBA

This question is intended to complement the hidden objects question in VBA hidden functions

What are the biggest, most common, or most unpleasant VBA pitfalls?

List all that can be described as

  • programmer beware
  • VBA behavior that requires painful and persistent workarounds.
  • Things that constantly make mistakes easy to create.
  • Things that confuse programmers
  • Unconventional syntax or behavior compared to other langauges, etc.
+5
source share
3 answers

Whole language?

Uh, I'll be specific: the fact that:

  • x = f(y)
  • f(y)
  • f y
  • Call f(y)

, , f Function Sub y ByRef ByVal.

, f :

  • x = f(y) ,
  • f(y) f , y - ByRef, ByVal
  • f y
  • Call f(y) f(y) , ByVal caveat

, f Sub:

  • f(y)
  • f y
  • Call f(y)

!

+4

VB.net - , Set,

Dim d as Object
Set D = CreateObject("SomethingUseful")

D = CreateObject("SomethingUseful")

IDE , ( ).

VB.Net/VB6, VBA.

+3

For any API calls on a 64-bit system or in Office 2010 x64, you need to rewrite the code. You can still write it for earlier versions of VBA, but you need to use VBA7 and / or Win64 compilation conditional variables. For instance:

#If VBA7 Then
   Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#Else
   Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#End If

Here's an article about it http://msdn.microsoft.com/en-us/library/ee691831(office.14).aspx

+3
source

All Articles