0

How do I loop/run the code According to a list in .txt file, until the list is ends ??

How do I loop/run the code According to a list in .txt file, until the list is ends ??

Sub FundData()

Dim TikerName As String

    TikerName = 'check & execute the names in list one after one in .txt file until it ends up

    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://example.com/index.php?name=" & TikerName, Destination:=Range( _
        "$A$1"))
        '.CommandType = 0
        .Name = "name=" & TikerName
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = """company"""
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
    ActiveSheet.Name = TikerName
    Sheets.Add After:=ActiveSheet
    ThisWorkbook.Save

End Sub
2
  • "ends up ??" huh? Commented Oct 26, 2016 at 19:44
  • There are about 300+ string in 300+ raw, mean last (row) string of the txt file, like TikerName.txt Commented Oct 26, 2016 at 19:48

1 Answer 1

0

Create a structure something like this:

Sub FundData()

    Dim TikerName As String

    Open "C:\somepath\sometextfile.txt" For Input As #1
    Do While Not EOF(1)
        Line Input #1, TikerName

        ' your main code goes here

    Loop
    Close #1
    ThisWorkbook.Save
End Sub
Sign up to request clarification or add additional context in comments.

3 Comments

showing not responding :( 300+ link access simultaneously from excel in same site, should it be ok??
@user176705 - I'm not sure I understand your comment. I can only guess that you mean that your question wasn't meant to be "How do I loop/run the code According to a list in .txt file, until the list is ends up??" but "How do I get sufficient resources so that Excel can perform 300 queries simultaneously". If so, I suggest you create a new question as that one is wildly different to what you asked.
Thanks for your nice understanding my friend. I will make a new question soon.

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.