SlowLearner
SlowLearner

Reputation: 3294

VBA Compiles in Word 2016 but not Word 2010

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

Upvotes: 3

Views: 175

Answers (3)

Slai
Slai

Reputation: 22876

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

Upvotes: 3

ThunderFrame
ThunderFrame

Reputation: 9461

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

Upvotes: 5

SlowLearner
SlowLearner

Reputation: 3294

Not as good as ThunderFrame's answer because I think it is probably more efficient to set a range as an object than the whole application, but here goes:

Sub testWd10()
    Dim wdApp As Object
    Set wdApp = Application

    If wdApp.Version > 14 Then
        wdApp.Documents(ActiveDocument.FullName).Range.FootnoteOptions.LayoutColumns
    End If
End Sub

Upvotes: 0

Related Questions