View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Matthew Herbert Matthew Herbert is offline
external usenet poster
 
Posts: 56
Default Trying to make a form for SEO.

On Jul 16, 2:07*pm, SEO_CodeMan wrote:
*Hello,
My name is Adam and I am a current SEO Researcher for a company called
Purple Trout.
I am currently trying to create a userform in excel that has three
command buttons and a textbox. Names are as follows:
txtBox1
cmdKeywords
cmdTitles
cmdDescriptions

The purpose of the textbox would be to input a URL. Purpose of
commandButton named Keyword is to search the URL's source code for the
list of HTML meta keywords and paste them into a sheet of excel.
Purpose of the cmdTitles commandButton is to search URL's source code
once again for the HTML Title, and the same goes for the description
with HTML description. I have successfully done the easy part and
created the form but have yet to find a way for the program to grab
each part of the source code and paste it into excel. Any help would
be great!
Thanks,
Adam


Adam,

There is quite a bit of information available on IE Automation. You
can actually do a search on "IE Automation". (I noticed that Tim
Williams posted a lot to these, so I started reading/searching for his
posts; I learned quite a bit from his posts). A very crude way is
below, but again, depending on the source code, you can target the
code more specifically. I've never done any web page development, so
I'm limited in knowledge, but I do know that web pages have tags and
you can use this to your advantage. A "tag" method is below, so play
around with the code and the potentiality of needing nested loops.
The code below will print the innertext of <a href... tags.

Note: I have not tested the code.

Best,

Matthew Herbert

'----------------------------------------------------
'GET IE OBJECT WITH URL
Sub TestIE()
Dim objIE As Object
Dim objTag As Object
Dim strNavigate As String

strNavigate = UserForm1.TextBox1

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate strNavigate
WaitForLoad objIE

End Sub

Sub WaitForLoad(IE As Object)

Do Until IE.Busy = False And IE.ReadyState = 4
Application.Wait Now() + TimeValue("0:00:01")
DoEvents
Loop
End Sub
'----------------------------------------------------

'----------------------------------------------------
'WITHIN YOUR COMMANDBUTTON CLICK EVENTS
'RUN SOMETHING LIKE THE FOLLOWING:

Private Sub CommandButton1_Click()
Dim objIE As Object

Set objIE = GetIE(UserForm1.TextBox1)
For Each objTag In objIE.document.all.tags("a")
'your code here
'you'll want to get the innertext of the object
'you may need to set up nested loop(s)
'setup an output to your worksheet here
Debug.Print objTag.innertext
Next objTag
End Sub

Function GetIE(sAddress As String) As Object

Dim objShell As Object, objShellWindows As Object, o As Object
Dim retVal As Object, sURL As String

Set retVal = Nothing
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows

'see if IE is already open
For Each o In objShellWindows
sURL = ""
On Error Resume Next
sURL = o.document.Location
On Error GoTo 0
If sURL < "" Then
If sURL Like sAddress & "*" Then
Set retVal = o
Exit For
End If
End If
Next o

Set GetIE = retVal
End Function
'----------------------------------------------------