Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA Compiles in Word 2016 but not Word 2010

Tags:

ms-word

vba

One of the new features that MS have introduced to MS Word since Word 2010 is LayoutColumns FootnoteOptions.

So the following line of code compiles in Word 2016: ActiveDocument.Range.FootnoteOptions.LayoutColumns but not in Word 2010 (I've not tested in Word 2013).

The conditional compiler statements don't seem to help... there is nothing for application version except VBA7 which includes Word 2010.

https://msdn.microsoft.com/VBA/Language-Reference-VBA/articles/compiler-constants

So this won't compile in Word 2010:

Sub testWd10()
#If Win64 And VBA7 Then
    ActiveDocument.Range.FootnoteOptions.LayoutColumns
#End If
End Sub

Compiler error - Method or data member not found

like image 598
SlowLearner Avatar asked Dec 12 '25 07:12

SlowLearner


2 Answers

Compiler directives won't help you. You need to determine the version, and use late-binding for the member calls that aren't in older versions of Word.

Sub testWd10()
  If Application.Version > 15 Then 'e.g. 15 is Word 2013, change as necessary
      Dim myRange As Object 'As Range
      Set myRange = ActiveDocument.Range
      myRange.FootnoteOptions.LayoutColumns 'Late-bound call
  End If
End Sub
like image 83
ThunderFrame Avatar answered Dec 13 '25 20:12

ThunderFrame


I am a bit late, but few more late binding alternatives:

Dim o As Object
Set o = ActiveDocument.Range.FootnoteOptions
On Error Resume Next
o.LayoutColumns = 3
On Error GoTo 0

A bit shorter and slower:

On Error Resume Next
CallByName ActiveDocument.Range.FootnoteOptions, "LayoutColumns", vbSet, 3
On Error GoTo 0

or:

On Error Resume Next
CVar(ActiveDocument.Range.FootnoteOptions).LayoutColumns = 3
On Error GoTo 0
like image 37
Slai Avatar answered Dec 13 '25 20:12

Slai