+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18

Thread: Import data from a web page

  1. #16
    Registered User
    Join Date
    08-18-2011
    Location
    Denver Colorado
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: Import data from a web page

    Here you go Leith. The second screen is run with station 436. The third is Statistics Table. Thank you again for working on this.

    Sean
    Attached Files Attached Files

  2. #17
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Import data from a web page

    Hello Sean,

    Thanks for the additional files. It was a big help in checking the code. The attached workbook has one button on the "Instructions" sheet called "Run Report". This macro calls up a UserForm I added that allows you to type in your user name and password. The password appears as asterisks in the text box. The button labeled "Log On" kicks off all the other macros for selecting the report, importing the table, and saving the CSV files.

    The only modification that needs to be made is to the "Log On" code. I do not know what the names of the user name input, password input, and submit button are. Perhaps you can add the needed names. The code appears below.
    
    Private Sub CommandButton1_Click()
    
        Dim I As Long
        Dim Password As Object
        Dim Shell As Object
        Dim SubmitBtn As Object
        Dim UserName As Object
        Dim Wnd As Object
        
            URL = "http://itinventory.v16.va.gov/report.cfm?rptid=3"
            
            Set ieApp = CreateObject("InternetExplorer.Application")
            ieApp.Visible = True
            ieApp.Navigate URL
    
                While ieApp.Busy Or ieApp.readyState <> 4: DoEvents: Wend
                
                Set Shell = CreateObject("Shell.Application")
                
                For Each Wnd In Shell.Windows
                    If Wnd.Hwnd = ieApp.Hwnd Then
                       Set ieDoc = Wnd.Document: Exit For
                    End If
                Next Wnd
                
                'Set Password = ieDoc.getElementById("Password")
                'Set UserName = ieDoc.getElementById("Username")
                'Set SubmitBtn = ieDoc.getElementById("Submit")
                
                UserName.Value = TextBox1
                Password.Value = TextBox2
                SubmitBtn.Click
                
            Set ieDoc = Wnd.Document
            SelectReport
            
            Set ieDoc = Wnd.Document
            ImportTable
            
          ' Open hyperlinks and save .CSV to a prompted location with a unique filename
            combinespreadsheets
            
            Unload Me
            
    End Sub
    Try out the attached workbook and let me know of any problems that occur or changes you would to make.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #18
    Registered User
    Join Date
    08-18-2011
    Location
    Denver Colorado
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: Import data from a web page

    Hello Leith,

    Firstly, thank your for all your time with this! Nothing I tried would work. I just tried running the macro, and after clicking the log on button (there is no user name or password required, just a va.gov user), I got a run time error 91: object variable or with block variable not set for this line of code:
    UserName.Value = TextBox1
    Since user name and password aren't necessary, I commented them out. It ran all the way through. One issue is the SUB combinespreadsheets() asks the user to indicate where the .CSV files, from the third screen, are saved. Could you put in an input box for the user to specify this location?

    Another is the imported table for the summary tab. The macro grabbed the first page after creating the report. I need it to open the link that created from running the report and import the subsequent table.

    And somewhere along the line, since everything runs from the instruction tab, the instructions get cleared, auto-filter and freeze frame are applied. I tried stepping through the macros as they run, but once they've started I can't change from the Instructions tab.

    Thank you again for all your time!


    Sean

    10:22- Now I'm getting a run time error 91 object variable or with block variable not set at this line (with user id/password commented) of IMPORT TABLE:
    For TR = 3 To TableObj.Rows.Length - 2
    Should this need another ie.app busy or ie.app readystate statement while the site is conducting the query?
    smb
    Last edited by Hoosaskin; 01-23-2012 at 12:28 PM. Reason: New run time error

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0