MS Word VB macro code, ran out of space on line

FrecklePaw
2StarLounger
Posts: 130
Joined: 12 Aug 2020, 08:40

MS Word VB macro code, ran out of space on line

Post by FrecklePaw »

I've got a really long list of items I want to do a mass replace for that I've got a macro for with at start of line:

FromArray = Array
ToArray = Array

When I run out of space on either line, how do I create a continuation of that line? It just suddenly runs out of space?

If I make a new line with a duplication of these, i.e.:

FromArray = Array
From Array = Array

I got undesired results, and it didn't work and seemed to favour the bottommost (new) line of code over the top.

How can I set it up for continuation so that it recognises all code under one Array at a time?

Thanks!

User avatar
HansV
Administrator
Posts: 78523
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: MS Word VB macro code, ran out of space on line

Post by HansV »

To continue an instruction on the next line, add a space followed by an underscore at the end of the line, then press Enter:

Code: Select all

    FromArray = Array("Item 1", "Item 2", "Item 3" _
        "Item 4", "Item 5", "Item 6", "Item 7", _
        "Item 8", "Item 9", "Item 10", "Item 11")
Best wishes,
Hans

FrecklePaw
2StarLounger
Posts: 130
Joined: 12 Aug 2020, 08:40

Re: MS Word VB macro code, ran out of space on line

Post by FrecklePaw »

I've done as above, i.e. space, underscore, Enter.
Then my second line starts

"Item 4")

But I get an error saying:

Compile error:

Expected: list separator or )

But I'm confused as I do have a )

If I try to add another item it doesn't improve, i.e.

"Item 4", "Item 5")

What am I doing wrong?

User avatar
HansV
Administrator
Posts: 78523
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: MS Word VB macro code, ran out of space on line

Post by HansV »

:stupidme:

I forgot the comma after "Item 3"

Code: Select all

    FromArray = Array("Item 1", "Item 2", "Item 3", _
        "Item 4", "Item 5", "Item 6", "Item 7", _
        "Item 8", "Item 9", "Item 10", "Item 11")
Best wishes,
Hans

FrecklePaw
2StarLounger
Posts: 130
Joined: 12 Aug 2020, 08:40

Re: MS Word VB macro code, ran out of space on line

Post by FrecklePaw »

aha! that's it. perfect - thank you :)