LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Upload a file to a web using VBA

There is a site on our company's INTRANET that I need to upload a file to.
This is a FORM that needs the fileName to be populated, but I have not been
able to get it to accept fileName from any means I have tried. I have ALL of
the other fields working and it is to the point all I need to do is manually
select the file, but I need to automate this.

I have been able to access the site, stuff all kinds of other info into the
websites varables, but I have NOT been able to stuff the fileName to upload.
Here is the code (including some failed attempts) to get the file name into
the web page.
First, I am opening the page and logging in with a userform ("fNTLogin")


Code:
Function ProcessScout() As Boolean
    Dim oScout As Object
    Dim ScoutWeb As String
    Dim fileName As String
    Dim newscoutname As String
    Dim F As fNTLogin
    'name of the file to upload
    newscoutname = "h:\Scout\ScoutInPut" & 
Application.Substitute(Format(Date, "yyyymmdd"), "/", "-") & ".txt"

    GetAccountList 'function to get a list of account numbers
    ScoutWeb = 
"http://internalWebsite.com/network_monitoring/servlet/network_monitoring"
    Set oScout = OpenScout(ScoutWeb) 'opens the site and gets the object 
'oScout'
    'waitforweb2 (oScout)
            While oScout.busy
        DoEvents
    Wend
    While oScout.ReadyState < 4
        DoEvents
    Wend
    spage = oScout.document.DocumentElement.outerHTML ' the the outer html 
for testing purposes
    webWait = oScout.document.Title

'test for logged in
    If InStr(spage, "Please enter your NT user name and password")  0 Then
'login
    Do While InStr(spage, "Please enter your NT user name and password")  0
     Set F = New fNTLogin  'Creates the login form
          F.Value1 = ""  'set username value to ""
          F.Value2 = ""  'set password value to ""
          F.Display  'shows the form
          pub_UserName = F.Result1 'sets the username for other logins
          pub_pw = F.Result2  'sets the pw for other logins
         Set F = Nothing 'distroys the form
         With oScout.document.form1
        .all.Item("user").Value = pub_UserName
        .all.Item("pass").Value = pub_pw
        .Submit
    End With
    While oScout.busy
        DoEvents
    Wend
    While oScout.ReadyState < 4
        DoEvents
    Wend
    spage = oScout.document.DocumentElement.outerHTML 'resetting spage for 
testing if logged in
Loop

    End If
  ' We are now logged in
    oScout.Navigate 
"http://internalwebsite.com:8070/network_monitoring/servlet/network_monitoring?reqType=cmLookupPage" 
' move to the page to upload account info
   While oScout.busy
        DoEvents
    Wend
    While oScout.ReadyState < 4
        DoEvents
    Wend
    oScout.document.form1.searchType.Value = "bulkaccount"
    oScout.document.form1.bulkLoadType.Value = "account"
    oScout.document.getElementById("divMAC").Style.visibility = "hidden"
    oScout.document.getElementById("divPhone").Style.visibility = "hidden"
    oScout.document.getElementById("divAccount").Style.visibility = "hidden"
    oScout.document.getElementById("divNode").Style.visibility = "hidden"
    oScout.document.getElementById("divBulkMAC").Style.visibility = 
"visible"
    oScout.document.form1.Mac.Value = ""
    oScout.document.form1.account.Value = ""
    oScout.document.form1.phone.Value = ""
    oScout.document.form1.Node.Value = ""
    oScout.document.form1.reqType.Value = "onDemandBatch"
    oScout.document.form1.Encoding = "multipart/form-data"

    With oScout.document.form1  'document name = "document" form name = 
"form1"
        .report(3).Click 'select the third report option  'this works
        .Email.Value = " ' this works
        .FileName.Value = "H:\Scout\ScoutInPut1-7-2010.txt"    'this does 
not error, but it does not stuff the name
    End With

  '  UploadFile oScout,  "H:\Scout\ScoutInPut1-7-2010.txt", "fileName" ' 
another failed attempt

'Failed attempt below
 '      Set Files = oScout.document.getElementsByTagName("input")
 '      For Each File In Files
 '
 '           If File.Type = "file" Then
 '               If SetFeatureTo Then
 '                   check.Checked = True
 '                  ' Exit Sub
 '               Else
 '                  ' check.Checked = False
 '                  ' Exit Sub
 '               End If
 '           End If
 '    '   End If
 '    '   r = check.Value
 '   Next


    oScout.document.form1.fileName.Value = "H:\Scout\ScoutInPut1-7-2010.txt" 
' no errors but does not populate     Call setfeature(oScout, "billing", 
True)
    Call setfeature(oScout, "ecx", True)
    Call setfeature(oScout, "gds", True)
    Call setfeature(oScout, "bacc", True)
    Call setfeature(oScout, "switch", True)
    With oScout.document.form1
        .all.Item("fileName").Value = "H:\Scout\ScoutInPut1-12-2010.txt"

        '.all.Item("pass").Value = pub_pw
        '.Submit.Click
    End With

    MsgBox "Please select file and pres Submit"   '<< this is to handle it 
in the
                'meantime until I get the stuffing of the file name working
    oScout.document.form1.Submit
    spage = oScout.document.DocumentElement.Title
    Debug.Print spage

    webWait = oScout.document.Title

End Function


Here is the webpage html code that needs to recieve the filename:

Enter Email Address:<br
<input type=text size=25 name=email value=""<br<br
Select File To Upload:<br
<input type=file name=fileName<br



Thanks
Bruce

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
File upload Chetan Excel Programming 1 August 31st 06 05:15 PM
Upload file on a server loopoo[_7_] Excel Programming 4 February 13th 06 02:25 AM
How can I upload a file to my webfolder? Jos Vens[_2_] Excel Programming 1 October 12th 05 07:44 PM
.csv file upload - unrecognized Kiran Setting up and Configuration of Excel 0 May 27th 05 05:30 PM
upload file name choice[_2_] Excel Programming 3 March 25th 05 10:38 PM


All times are GMT +1. The time now is 06:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"