Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default Upload a file to a web using VBA

Typically the only way to assign the file on a HTML form file element is to
actually click the button and select the file.
The input element's functionality is not exposed to scripting or automation
for security reasons.

If it were possible to set it programmatically (or by pre-populating the
path in the page HTML) then it would be possible to grab files without folk
knowing. I realize this is an intranet application, but I'm not sure
there's any way to relax that security.

Tim


"Bruce" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Upload a file to a web using VBA


Have you been able to enter you email address?


The tag "Input" is an array You may be putting filename in the wrong
index of the array. Indexing will alway start with 0 (which is item 1).
I can't tell from your code how many Input tags are on your page.

One thing that I've been able to open the webpage manually (this
doesn't work when the page is called from VBa) and then enter the a
string into the input box. I usually just put my name into the box I'm
trying to located. Then use the developers tool on the IE explorer by
typing F12. There is a search box in the developers tool where you can
search for the string that you put into the box.


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=170493

Microsoft Office Help

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Upload a file to a web using VBA

I have been able to populate email...
I think Tim is gonna be right, I have seen several other referances to
that...
I will try the array method and see if that works.
I may have to try sendkey, if I can figure out how to place the curser in
the right box...

Thanks
Bruce

"joel" wrote in message
...

Have you been able to enter you email address?


The tag "Input" is an array You may be putting filename in the wrong
index of the array. Indexing will alway start with 0 (which is item 1).
I can't tell from your code how many Input tags are on your page.

One thing that I've been able to open the webpage manually (this
doesn't work when the page is called from VBa) and then enter the a
string into the input box. I usually just put my name into the box I'm
trying to located. Then use the developers tool on the IE explorer by
typing F12. There is a search box in the developers tool where you can
search for the string that you put into the box.


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread:
http://www.thecodecage.com/forumz/sh...d.php?t=170493

Microsoft Office Help


Reply
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 10:22 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"