Solved

Excel VBA QueryTable Loop

Posted on 2010-08-18
4
1,447 Views
Last Modified: 2012-05-10
In Excel VBA, how would I use QueryTables to loop through, for example, on http://translate.reference.com/ to supply a word, say English "two" and translate into every language on its drop down to>> list. Then store results in Sheet1 like
Afrikaans twee
Albanian dy
Arabic ¿¿¿¿¿
...
French deux
...
Yiddish ¿¿¿¿¿


Regards
Brian
0
Comment
Question by:canesbr
4 Comments
 
LVL 11

Expert Comment

by:thydzik
Comment Utility
what do you mean querytables? is this a static table you have, or are you referring to going online?
what do you mean by 'on its dropdown list'?
this is possible but need there clarifications.
is it possible to attach an example spreadsheet?
0
 
LVL 2

Expert Comment

by:insaneCFC
Comment Utility
0
 
LVL 33

Expert Comment

by:Norie
Comment Utility
Brian

If you wanted to use QueryTables then the first thing you would probably need to do is find out if there is a URL that does the translation using the text entered and the language(s) picked.

For example this translates 'house' from English to Icelandic.

http://translate.reference.com/translate?query=house&src=en&dst=is&v=1.0

If you need to do this for multiple words and languages you would need to construct this URL using string concatenation.

Then you would need to use this URL for the QueryTable, which I assume is a web query.

You might have problems with that though, I'm afraid the URL doesn't return any data according to Excel.
0
 

Accepted Solution

by:
canesbr earned 0 total points
Comment Utility
I have an intermediate solution
Please see code attached.
I will ask a follow up in another question.
Regards
Brian
Option Explicit
Sub GetTranslationAllLanguagesSAS()

    Dim myword As String
    Dim L As Range
    Dim ss As Worksheet
    Dim mfr As Range
    
    Set ss = Sheets(1)
    Range("b2").Resize(Cells(Rows.Count, 1).End(xlUp).Row, 2).ClearContents
    Application.ScreenUpdating = False
        myword = Range("b1")
        For Each L In Range("Languages")
           With ss.QueryTables(1)
                .Connection = _
                 "URL;http://translate.reference.com/translate?query=" & _
                  myword & "&src=en&dst=" & L & "&v=1.0"
                .Refresh BackgroundQuery:=False
            End With
         Set mfr = ss.Columns(1).Find(What:="Translation:", LookIn:=xlValues, _
         LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext)
         If Not mfr Is Nothing Then
            L.Offset(, 1).Value = Mid(ss.Cells(mfr.Row, 1), 14, 256)
            L.Offset(, 2).Value = ss.Cells(mfr.Row + 1, 1)
         End If
        Next L
        Columns.AutoFit
    Application.ScreenUpdating = True
End Sub
Sub Macro1() 'macro above modified from this recorded while editing querytable.  by d guillett
    Range("A5").Select
    With Selection.QueryTable
        .Connection = _
        "URL;http://translate.reference.com/translate?query=two&src=en&dst=tl&v=1.0"
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
End Sub

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now