Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50112

How do I send this variable to a text box?

$
0
0
Hello,

Was hoping someone might be able to assist with this problem. My macro (thats attached) determines todays date, and looks in column A for the last date in the column, determines the amount of days that has elapsed between the two dates. Once it figures that out, it opens a webpage, and enters that number into a text box at the top of this webpage, and executes the search Test Example - Dates Column.xlsmbutton.

Problem is, Im getting not getting any error from VBE, but the script doesnt seem to be excuting, and Im not sure why. I thought
Code:

Application.Find
was the correct statement to use to find the variable and pass it, but I think thats where the script is being caught up. Also there is a drop down on the webpage that I want Excel to select the option "In Excel", but I can do that after. Right now Im just trying to pass this number (I described above) to the webpage.

Any idea how I fix this? :eek:


If you dont want to open the attachment, here is the code

Code:


Sub Example()
    Dim ie As SHDocVw.InternetExplorer  'Requires reference to "Microsoft Internet Controls"
    Dim strKeyword As String
    Dim lngStartAt As Long
    Dim lngResults As Long
    Dim doc As MSHTML.HTMLDocument      'Requires reference to "Microsoft HTML Object Library"
    Dim extractedHTML As String    'create a variable to hold the text
    Dim iStart, iEnd As Integer    'start and end points for the substring
    Static X As Long
    X = DateDiff("d", Range("A" & Rows.Count).End(xlUp).Value, Date)
   
   
    Set ie = New SHDocVw.InternetExplorer
    lngStartAt = 1
    lngResults = 100
    Strx = Application.Find("(", X)
    ie.Navigate "http://www.pge.com/cgi-bin/pipeline/...mand_search.pl" & strKeyword
    Do Until ie.readyState = READYSTATE_COMPLETE: DoEvents: Loop
    Set iedoc = ie.document
 
'set iStart to 1 for the first position to strat from for looping through the string
iStart = 1
'loop for 10 results
 For i = 1 To 10
 
    'get the element with ID of search - this is where the results start
    extractedHTML = iedoc.getElementById("search").innerHTML
    'find the first  as this will be the first real google search link
    iStart = InStr(iStart, extractedHTML, "", vbTextCompare) + Len("")
    'locate the next  as this will be the end of the URL
    iEnd = InStr(iStart, extractedHTML, "", vbTextCompare)
   
    'extract the text
    extractedHTML = Mid(extractedHTML, iStart, iEnd - iStart)
    'replace bold text formats
    extractedHTML = Replace(extractedHTML, "", "")
    extractedHTML = Replace(extractedHTML, "", "")
   
    'write result to Cells
    Range("A" & i + 1) = extractedHTML
Next i
End Sub

Test Example - Dates Column.xlsm

Viewing all articles
Browse latest Browse all 50112