VBA - Pasting Variable String From Host Application to a specific Textbox in Internet Explorer -


i have variable string phn storing phone number in text form in vba project working on. once have application determine phone number, need activate specific internet explorer page that has been loaded , ready go, locate specific text box call phone number (not sure how determine actual name of text box), paste string phn in box. once done, should automatically hit enter.

here compiled code far:

sub pbx_ic_dialer     '<macro = pbx_ic_dialer>     '<shortcut = shift+ctrl+p>     '<desc = recorded 7/25/2016 1:11:07 pm>     on error resume next      dim resp string  'response inputbox, allows macro determine number dialed.     dim phn string   'phone number pasted dialer     dim l integer    'left value of first digit of phone # locations in pc screen     dim r integer    'value of last digit of phone number in pc screen     dim row integer  'row # of entire phone number     dim resp2 integer'allows if statement below check if # 1-9      ' values of first "selection values" go here. allows updated simultaneously     l =     16      'left     r = l + 11      'do not update one. based on "l" value     row =   4      activesession         .inputmode = 1         resp = inputbox("line number? (or may type in phone number manual call)")         resp2 = cint(resp)         if (resp2 <> 1 , resp2 <> 2 , resp2 <> 3 , resp2 <> 4 , resp2 <> 5 , resp2 <> 6 _             , resp2 <> 7 , resp2 <> 8 , resp2 <> 9)             phn = resp         elseif resp2 = 1             .copy l, row, r, row             phn = clipboard         elseif resp2 = 2             .copy l, row + 1, r, row + 1             phn = clipboard         elseif resp2 = 3             .copy l, row + 2, r, row + 2             phn = clipboard         elseif resp2 = 4             .copy l, row + 3, r, row + 3             phn = clipboard         elseif resp2 = 5             .copy l, row + 4, r, row + 4             phn = clipboard         elseif resp2 = 6             .copy l, row + 5, r, row + 5             phn = clipboard         elseif resp2 = 7             .copy l, row + 6, r, row + 6             phn = clipboard         elseif resp2 = 8             .copy l, row + 7, r, row + 7             phn = clipboard         elseif resp2 = 9             .copy l, row + 8, r, row + 8             phn = clipboard         else             msgbox "there unknown error has occured, , operation cannot completed @ time." & chr$(13) & "please review macro , try again.", vbcritical         end if         .inputmode = 0     end end sub 

so have gotten point can activate internet explorer... now, how paste string phn specific text box located in page activated? if know in while in developer mode of ie, can give more detailed response on name of text box.

instead of using appactivate, loop through items of shellwindows until find correct ie object (based on title, url, etc). there, comes down finding correct controls on webpage, using getelementbyid or 1 of other methods on ie.document. figuring out way specific element might easy or might hard, depending on website you're working with. in general, if open developer mode , inspect textbox , button, you'll want check "name" or "id" tag, easiest ways identify these objects. depend on document, , you'll have ask more specific situation (or through javascript/dom questions on stackoverflow, full of sort of how-do-i-find-my-element questions).

once have elements, simple modifying contents of textbox element value of phn, simulating click or submission of form via click() or submit().

sample (something along these lines should work):

dim shellwins shellwindows dim ie internetexplorer dim txtbox object dim submitbtn object  set shellwins = new shellwindows each win in shellwins     if win.locationurl = "my_url"         set ie = win     end if next  if not ie nothing     set txtbox = ie.document.getelementbyid("my_textbox_id")     set submitbtn = ie.document.getelementbyid("my_button_id")      txtbox.value = phn     submitbtn.click end if  set shellwins = nothing 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -