Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel macros - Too many line continuations

Tags:

excel

vba

I have a "large" SQL query (like 200 lines)...

dim query as string
query = "..................................." & _
        "..................................." & _
           .... Like a lot lines later...
        "..................................."

function query,"sheet 1"

When I do this, Excel says "Too many line continuations."

What is the best way to avoid this?

like image 952
pojomx Avatar asked May 10 '10 20:05

pojomx


3 Answers

There's only one way -- to use less continuations.

This can be done by putting more text on a line or by using concatenation expressed differently:

query = ".........."
query = query & ".........."
query = query & ".........."

But the best is to load the text from an external source, as a whole.

like image 110
GSerg Avatar answered Nov 09 '22 19:11

GSerg


Split the query into several sections:

query = _
  "............" & _
  "............" & _
  "............"
query = query & _
  "............" & _
  "............" & _
  "............"
query = query & _
  "............" & _
  "............" & _
  "............"
like image 40
Guffa Avatar answered Nov 09 '22 20:11

Guffa


So far I found this...

Call AddToArray(query, "...")
Call AddToArray(query, "...")
... a lot lines later...
Call AddToArray(query, "...")

*edit: Forgot to add:

Sub AddToArray(myArray As Variant, arrayElement As Variant)

If Not IsArrayInitialized(myArray) Then
    ReDim myArray(0)
    myArray(0) = arrayElement
Else
    ReDim Preserve myArray(UBound(myArray) + 1)
    myArray(UBound(myArray)) = arrayElement
End If

End Sub

Source: link text X( thankyou

(Still waiting for better ways to do this...) thankyou :P

like image 1
pojomx Avatar answered Nov 09 '22 19:11

pojomx