3

Is there a more compact and/or conventional way to write this?

With ActiveSheet.QueryTables.Add(Connection:="URL;http://carbon.brighterplanet.com/flights.txt", Destination:=Range("A2"))
    .PostText = "origin_airport=MSN&destination_airport=ORD"
    .RefreshStyle = xlOverwriteCells
    .SaveData = True
    .Refresh
End With

Is there a reason that Connection is written on the first line while PostText is on the second line?

1
  • I don't know if I really love doing this in the first place, but you could use line continuation (_) to make this fit on the screen better... With ActiveSheet.QueryTables.Add( _ Connection:="URL;http://carbon.brighterplanet.com/flights.txt", _ Destination:=Range("A2")) (Split the lines at the _ since this does not come out correctly in comments...) Commented Jun 22, 2012 at 16:58

1 Answer 1

4

Connection and Destination are required arguments to the Add function, while PostText (etc) is a property of the QT. The Add function will neither work without the Connection nor with the property passed as an argument.

See this and this for additional reference.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.