1

I am trying to use the Workbooks.Open Method within Microsoft Excel VBA 2010 and I am receiving a Compile error stating that it is expecting "=". Have I mistyped the code?

Workbooks.Open ( _
    Filename:= FromBook, _
    UpdateLinks:= xlUpdateLinksNever, _
    ReadOnly:= False, _
    Format:= 5, _
    Password:= "", _
    WriteResPassword:= "", _
    IgnoreReadOnlyRecommended:= "", _
    Origin:= "", _
    Delimiter:= "", _
    Editable:= "", _
    Notify:= "", _
    Converter:= "", _
    AddToMru:= "", _
    Local:= "", _
    CorruptLoad:= xlNormalLoad)
Community
  • 1
  • 1
TroyPilewski
  • 359
  • 8
  • 27

1 Answers1

3

That way is expecting the value to be assigned to a variable IE:

Dim myWB as Workbook

Set myWB = Workbooks.Open ( _
    Filename:= FromBook, _
    UpdateLinks:= xlUpdateLinksNever, _
    ReadOnly:= False, _
    Format:= 5, _
    Password:= "", _
    WriteResPassword:= "", _
    IgnoreReadOnlyRecommended:= "", _
    Origin:= "", _
    Delimiter:= "", _
    Editable:= "", _
    Notify:= "", _
    Converter:= "", _
    AddToMru:= "", _
    Local:= "", _
    CorruptLoad:= xlNormalLoad)

If you don't really need it that way, you may do a call instead:

Call Workbooks.Open ( _
        Filename:= FromBook, _
        UpdateLinks:= xlUpdateLinksNever, _
        ReadOnly:= False, _
        Format:= 5, _
        Password:= "", _
        WriteResPassword:= "", _
        IgnoreReadOnlyRecommended:= "", _
        Origin:= "", _
        Delimiter:= "", _
        Editable:= "", _
        Notify:= "", _
        Converter:= "", _
        AddToMru:= "", _
        Local:= "", _
        CorruptLoad:= xlNormalLoad)
Sgdva
  • 2,800
  • 3
  • 17
  • 28
  • 1
    `Call` is redundant. You can just use: `Workbooks.Open _ Filename:= FromBook, _ UpdateLinks:= xlUpdateLinksNever, _ ReadOnly:= False, _ Format:= 5, _ Password:= "", _ WriteResPassword:= "", _ IgnoreReadOnlyRecommended:= "", _ Origin:= "", _ Delimiter:= "", _ Editable:= "", _ Notify:= "", _ Converter:= "", _ AddToMru:= "", _ Local:= "", _ CorruptLoad:= xlNormalLoad` – ThunderFrame Jun 30 '16 at 20:01
  • @ThunderFrame If I don't use the above examples then I get Compile errors – TroyPilewski Jun 30 '16 at 20:05
  • 1
    @TroyPilewski removing the `Call` requires removing the leading `(` and trailing `)` – ThunderFrame Jun 30 '16 at 20:06
  • 1
    @ThunderFrame Sorry, I apologize. The above examples work. As well as yours ThunderFrame if I remove the parenthesis's. – TroyPilewski Jun 30 '16 at 20:07
  • 1
    For standardizing purposes, I always use call for subs or things like this so I know I'm just doing a routine – Sgdva Jun 30 '16 at 20:10
  • 1
    Also, as you're using named arguments, and many of them are the default, you can remove the unnecessary ones, like `Password:= ""` and `WritePassword:= ""`. They're unused and just add clutter to your code. – ThunderFrame Jun 30 '16 at 20:11
  • 1
    @Sgdva For standardizing purposes, you should be *removing* `Call` statements. That's the approach that Rubberduck VBA takes when inspecting and quick-fixing code. – ThunderFrame Jun 30 '16 at 20:14
  • The *only* time that a call statement is necessary is when you (maliciously) want to call a procedure that requires arguments on the *same* line as a label. – ThunderFrame Jun 30 '16 at 20:16