?
Solved

Excel VBA QueryTable Loop

Posted on 2010-08-18
4
Medium Priority
?
1,616 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 11

Expert Comment

by:thydzik
ID: 33472406
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
ID: 33474470
0
 
LVL 34

Expert Comment

by:Norie
ID: 33475560
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
ID: 33497742
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

801 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