• Status: Solved
  • Priority: Medium
  • Security: Private
  • Views: 20
  • Last Modified:

How to modify vba code to input data instead of extracting data from an element ID?

I have the below code that I use to extract data, but I need to modify it to input data into the same element ID.

Sub GetTicketData()

    Dim objIE As SHDocVw.InternetExplorer
    Dim objShell As SHDocVw.ShellWindows
    Dim objIEDoc As MSHTML.HTMLDocument
    Dim objFound As MSHTML.HTMLBaseElement
    Dim strURL As String
    Dim blnFoundWebSite As Boolean
    Dim objDialog As FileDialog
    Dim objFSO As Scripting.FileSystemObject
    Dim objText As Scripting.TextStream
    Dim objDebugFile As Scripting.TextStream
    
    Dim varFrame As Variant
    Dim varFrame2 As Variant
    Dim objFrameDoc As MSHTML.HTMLDocument
    Dim objFrameDoc2 As MSHTML.HTMLDocument
    Dim i As Integer
    Dim j As Integer
    
    Dim objElem As MSHTML.HTMLBaseElement
    Dim objElemDoc As MSHTML.HTMLDocument
    Dim objElem2 As MSHTML.HTMLBaseElement
    Dim objElemDoc2 As MSHTML.HTMLDocument

        
    Set objShell = New SHDocVw.ShellWindows
    Set objFSO = New Scripting.FileSystemObject
    
    ' **** Set the Web Address Here ****
    strURL = "https://servman/sm/index.do"
    
    
    
    ' Look for the appropriate open IE Window
    For Each objIE In objShell
        If TypeOf objIE.document Is MSHTML.HTMLDocument Then
            Set objIEDoc = objIE.document
            If Not (objIEDoc Is Nothing) Then
                If objIEDoc.url = strURL Then
                    blnFoundWebSite = True
                    Exit For
                End If
            End If
        End If
    Next
    
    Set objFrameDoc2 = objIEDoc

    If blnFoundWebSite Then
        ' Make sure IE is done loading the page
        Do Until Not objIE.Busy
            DoEvents
        Loop
        
        ' Make Sure we had some frames returned
        If objIEDoc.frames.Length > 0 Then
            ' Get the Document from the 1st Frame
            Set varFrame = objIEDoc.frames.Item(0)
            Set objFrameDoc = varFrame.document
            
            ' Get the Detail Frame (Sub Frame #2)
            If objFrameDoc.frames.Length > 1 Then
                Set varFrame2 = objFrameDoc.frames.Item(1)
                Set objFrameDoc2 = varFrame2.document
                
                'Title
                Set objFound = objFrameDoc2.getElementById("X95")
                If objFound Is Nothing Then
                    Range("K5").Value = ""
                Else
                    Range("K5").Value = objFound.Value
                End If
                
                
            Else
               
                'Title
                Set objFound = objFrameDoc.getElementById("X95")
                If objFound Is Nothing Then
                    Range("K5").Value = ""
                Else
                    Range("K5").Value = objFound.Value
                End If
                
                                
            End If ' objFrameDoc.frames.Length > 1
        End If ' objIEDoc.frames.Length > 0
        
        
        
    End If
    
    
    Set objIE = Nothing
    Set objShell = Nothing
    Set objIEDoc = Nothing
    Set objIEDoc = Nothing
    Set objFound = Nothing
    Set objDialog = Nothing
    Set objFSO = Nothing
    Set objText = Nothing
    Set objDebugFile = Nothing
End Sub

Open in new window

0
kbay808
Asked:
kbay808
  • 3
  • 2
1 Solution
 
Robberbaron (robr)Commented:
confirm you are trying to  'write data' to the web report ?
0
 
kbay808Author Commented:
I'm not sure about the term web report.  I think of it as a web form.  I attached a screen shot of the website with a red box around the box with the target data that I want to replace.
0
 
kbay808Author Commented:
0
 
Robberbaron (robr)Commented:
i dont think you can do what you ask...

I believe you can write to the element, but it wont update.  Unless you save as a new 'local' HTML document and then reopen that.

               'Title
                Set objFound = objFrameDoc.getElementById("X95")
                If objFound Is Nothing Then
                    'cant write to it
                Else
                     objFound.Value = "MY new DATA"
                End If

Open in new window


what you are trying to do is commonly done by javascript on the web page itself.
0
 
kbay808Author Commented:
It worked!!!  Thank you very much
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now