VBA How to download a generated file from IE

Hi guys,
Apologies if this is an easy one, I couldn't find anything that helped me with my problem and was hoping someone might point me in the right direction for which object/argument to use.
I'm trying to automate the downloading of a report, it will be a CSV file however it's not a static address (i.e. www.hello.com/files/goodbye.csv)
The website is a CMS with database backend and upon clicking a button, the report is generated and the user will be prompted to download a resulting file (once it has been prepared).
It is this action that I am trying to automate, however I'm not sure how to get IE to click the button and automatically saving instead of prompting the user at all (ideally this will be done with IE Visible being false in the end).
Any help would be greatly appreciated!
Best regards,
Jeff.

You can use an API to do the work too!
Option Explicit
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, ByVal hwnd2 As Long, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Public Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA"
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As
Long) As Long
Public Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Public Const TCM_SETCURFOCUS As Long = &H1330&
Public Const BM_CLICK As Long = &HF5&
Private Const WM_COMMAND As Long = &H111
Sub Download()
Dim i As Long, res As Long
Dim hWndUI As Long, hWndBtn As Long
Dim timeOut As Double
Const cClsName As String = "#32770" ' same classname for all the control
windows we'll need
ReDim aWinText(1 To 3) As String
aWinText(1) = "File Download - Security Warning"
aWinText(2) = "Save As"
aWinText(3) = "Download complete"
' 1, get the File download window and click Save
' 2, get the Save As window and click Save
For i = 1 To 2
hWndUI = 0
timeOut = Timer + 5
While hWndUI = 0 And Timer < timeOut
Sleep 100&
hWndUI = FindWindow(cClsName, aWinText(i))
Wend
If hWndUI = 0 Then
' eg bad url
Err.Raise 12345, , "didn't get " & vbCr & aWinText(i)
End If
SetForegroundWindow hWndUI
Sleep 100&
hWndBtn = FindWindowEx(hWndUI, 0&, "Button", "&Save")
Sleep 200&
res = SendMessage(hWndBtn, TCM_SETCURFOCUS, 1, ByVal 0&)
'res = SendMessage(hWndBtn, BM_CLICK, ByVal 0&, ByVal 0&)
res = PostMessage(hWndBtn, BM_CLICK, ByVal 0&, ByVal 0&)
res = SendMessage(hWndBtn, WM_COMMAND, 0&, 0&)
Next
' 3, wait until Download complete appears
hWndUI = 0
timeOut = Timer + 10 ' increase timeOut with bigger files
While hWndUI = 0 And Timer < timeOut
hWndUI = FindWindow(cClsName, aWinText(3))
Wend
' optional open folder
hWndBtn = FindWindowEx(hWndUI, 0&, "Button", "Open &Folder")
res = SendMessage(hWndBtn, TCM_SETCURFOCUS, 1, ByVal 0&)
res = PostMessage(hWndBtn, BM_CLICK, ByVal 0&, ByVal 0&)
' res = SendMessage(hWndBtn, BM_CLICK, ByVal 0&, ByVal 0&)
res = SendMessage(hWndBtn, WM_COMMAND, 0&, 0&)
DoEvents
End Sub
Sub Test1()
Dim url As String
Dim objIE As Object
On Error GoTo errH
url = "http://social.microsoft.com/Forums/getfile/25241/"
' iso IE suggest add a WebBrowser control to a sheet or a userform
' and use that rather than starting an instance of IE
Set objIE = CreateObject("internetexplorer.application")
objIE.Navigate url
Download
done:
On Error Resume Next
objIE.Quit
Exit Sub
errH:
MsgBox Err.Description
End Sub
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

Similar Messages

  • How to delete the Generated files from application server(open hub)?

    hi experts,
    when i try to execute process chain the DTP it is giving below dump. Exception CX_RSBK_REQUEST_LOCKED logged.
    when i execute the DTP manually and trying to delete the previous request, it is giving for dump ITAB_DUPLICATE_KEY.
    so to delete the generated file from application server, how to delete it for specific dates?
    Information on where terminated
    Termination occurred in the ABAP program "GPD6S3OE0BCVGC6L9DBNVYQARZM" - in
    "START_ROUTINE".
    The main program was "RSBATCH_EXECUTE_PROZESS ".
    In the source code you have the termination point in line 2874
    of the (Include) program "GPD6S3OE0BCVGC6L9DBNVYQARZM".
    The program "GPD6S3OE0BCVGC6L9DBNVYQARZM" was started as a background job.
    and when i check the dump it is point out at below code
    " Populate the lookup table for 0STOR_LOC
    SELECT * from /BI0/TSTOR_LOC
    into CORRESPONDING FIELDS OF table L_0STOR_LOC_TEXT
    FOR ALL ENTRIES IN SOURCE_PACKAGE WHERE
    STOR_LOC = SOURCE_PACKAGE-STOR_LOC.
    but the programme is syntactically correct only.
    how to rectify the issue.
    regards
    venuscm
    Edited by: venugopal vadlamudi on Sep 28, 2010 1:59 PM

    hi experts,
    We have written start routine to get the storage location text and sending to File located at Application server through OPEN HUB.
    here is the code written in the Transformations
    In the global section
    Text for 0STOR_LOC
        DATA: l_0stor_loc_text TYPE HASHED TABLE OF /bi0/tstor_loc
              WITH UNIQUE KEY stor_loc.
        DATA: l_0stor_loc_text_wa TYPE /bi0/tstor_loc.
    and in the code to get the text
    " Populate the lookup table for 0STOR_LOC
        *SELECT * from /BI0/TSTOR_LOC*
          into CORRESPONDING FIELDS OF table L_0STOR_LOC_TEXT
          FOR ALL ENTRIES IN SOURCE_PACKAGE WHERE
                  STOR_LOC = SOURCE_PACKAGE-STOR_LOC.
    im sure there is problem with the Routine only. i think i need to change the code if so please provide me the modified one.
    thanks
    venuscm
    Edited by: venugopal vadlamudi on Sep 29, 2010 9:37 AM

  • How to download a pdf file from the server from an strut application?

    Hi,
    I wan to download a pdf file from the server side to local system. Please help me how i use the down load option.

    Read up on the Struts download action [1].
    And next time, please post in the relevant forum, one of the web-tier ones [2].
    [1] http://wiki.apache.org/struts/StrutsFileDownload
    [2] http://forum.java.sun.com/category.jspa?categoryID=20
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    ----------------------------------------------------------------

  • How to download a .pdf file from a JavaMail application?

    hi to all,
    iam unable to download a .pdf file from a mailserver using
    my javamail application.i have downloaded all kind of files except .pdf.
    my code snipnet:
    public static void dumpPart(Part p) throws Exception {
    //     if (p instanceof Message)          dumpEnvelope((Message)p);
              System.out.println("CONTENT-TYPE: " + p.getContentType());
              Object o = p.getContent();
              if (o instanceof String) {
                   System.out.println("This is a String");
                   System.out.println((String)o);
                   } else if (o instanceof Multipart) {
                        System.out.println("This is a Multipart");
                        Multipart mp = (Multipart)o;
                        int count = mp.getCount();
    System.out.println("****************************************");
    System.out.println("count" + count);
    System.out.println("****************************************");
                        for (int i = 0; i < count; i++){
                             System.out.println("CONTENT-TYPE: " + p.getContentType());
                             dumpPart(mp.getBodyPart(i));
                        } else if (o instanceof InputStream) {
                             System.out.println("This is just an input stream");
                             InputStream is = (InputStream)o;
                             String filename=System.currentTimeMillis()+".exe     ";
                             FileOutputStream fos=new FileOutputStream(filename);
                             int c;
                             while ((c = is.read()) != -1)
                                  //System.out.write(c);
                                  fos.write((char)c);
    }//dumpPart
    what's wrong with this code?
    Nagaraju.G

    fos.write((char)c);Converting the byte to a char is unnecessary and probably harmful. Just do this: fos.write(c);

  • How to download a clob file from a table to my local drive?

    Hii Everyone,
    I'm havig a table of this structure
    Create table r_dummy
    c_clob_file clob
    How to download this file into my local drive?Please give me some hints.Can this be done using dbms_lob??
    Regards
    Raghu.

    You need to share a directory on your local drive and give permissions for the database server to write a file on your local drive. Or you may create the file on your database server and copy the same to your local drive.
    conn / as sysdba
    create or replace directory ext_tab_dir as 'C:\ExtTab_Dir';
    /* you may need to give a network path in place of C:\ExtTab_Dir if you want to create the file on your local drive. The directory should be created manually by you on the file system*/
    grant read, write on directory ext_tab_dir to scott;
    conn scott/tiger
    declare
            clb clob;
            l_output utl_file.file_type;
            len integer(6);
            vstart integer(6):=1;
            bytelen integer(6):=32000;
            my_vr varchar2(32000);
            x integer(6);
    begin
             l_output := utl_file.fopen('EXT_TAB_DIR','Clob_File.txt','w',32767);
            select c_clob_file into clb
             from r_dummy;
             len:=dbms_lob.getlength(clb);
             x:=len;
            while vstart < len and bytelen > 0
            loop
                dbms_lob.read(clb,bytelen,vstart,my_vr);
                utl_file.put(l_output,my_vr);
                utl_file.fflush(l_output);
                vstart:=vstart+bytelen;
                x:=x-bytelen;
                if x< 32000 then
                   bytelen := x;
                end if;
            end loop;
            utl_file.fclose(l_output);
    exception when others then
            utl_file.fclose(l_output);
            raise;
    end;
    /Edited by: Preta on Sep 29, 2010 10:53 AM

  • How to download a text file from the server

    hi everyone,
    can anyone tell me how to download and read a text file from the server and saved in into resource folder.
    with regards
    pallavi

    its really easy
    To read from server, use something like:
    HttpConnection connector = null;
    InputStream inp_stream = null;
    OutputStream out_stream = null;
    void CloseConnection()
         if(inp_stream!=null)inp_stream.close();
         inp_stream=null;
         if(out_stream!=null)out_stream.close();
         out_stream=null;
         connector.close();
         connector = null;
    public void getResponse(String URL,String params)
      try
         if(connector==null)connector = (HttpConnection)Connector.open(URL);//URL of your text file / php script
         connector.setRequestMethod(HttpConnection.POST);
         connector.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.1");
         connector.setRequestProperty("content-type", "application/x-www-form-urlencoded");
         //connector.setRequestProperty("charset","windows-1251");
         //*** If you need to send ("arg1=value&arg2=value") arguments to script use this:
         out_stream = connector.openOutputStream();
         byte postmsg[] = params.getBytes();
         out_stream.write(postmsg);
         int rc = connector.getResponseCode();//in any case here connection will be opened & closed
         if (rc != HttpConnection.HTTP_OK)
              CloseConnection();
              throw new IOException("HTTP response code: " + rc);
         inp_stream = connector.openInputStream();
         int pack_len = inp_stream.available();
         byte answ[]=new byte[pack_len];
         inp_stream.read(answ);
         CloseConnection();
         ProcAnswer(answ);//process received data
      catch(Exception ex)
         System.err.println("ERROR IN getResponse(): "+ex);
    } And you can read from resource file like
    public void loadFile(String filename)
        DataInputStream dis = new DataInputStream(getClass().getResourceAsStream("/"+filename));
        String str="";
        try
             while (true)
                ch = dis.read();//read character
                if(ch=='\r')continue;//if file made in windows
                if(ch=='\n' || ch==-1)//end of line or end of file
                    if(str.length()==0)continue;//if empty line
                    //do some thing with "str"
                    if(ch==-1)break;//it was last line
                    str="";//next line
                    continue;
                 str+=(char)ch;
           dis.close();
       catch (Exception e)
           System.err.println("ERROR in loadFile() " + e);
    }Welcome! =)
    Edited by: MorskoyZmey on Aug 14, 2008 3:40 AM

  • How to download converted .docx files from Adobe?

    I have converted five .pdf files into .docx files, but when I click on "the download icon" after putting a "check" in the box before the first converted file, nothing happens? 
    Is there a process to use?  I am using a PC using Windows 7 Ultimate Operating System, and my internet browser is IE 9.  I cannot upgrade to IE 10 as it compromises my MSN mail account: Outlook.com.
    I have tried to read all other answers to questions about this same issue, but none address the simple process of downloading a converted .pdf file back onto one's PC.
    Thanks for your help, Thomboy

    The trouble with these kind of situations is that an applet runs on the client. If you want an applet to connect to a specific server (which means the client makes a connection to that server), you basically have to give the entire world access rights to that server. I don't think your friendly local administrator will be too happy with such a prospect.
    What you could do is put a man in the middle. Don't upload to the file server directly, but to for example the web server where the applet was downloaded from, for example by making a servlet available that takes a HTTP file upload. When that upload is complete, send the file from your man in the middle server to the file server using whatever method you like/have available/know how to code. In this situation only your web server needs access to the file server, which is far easier to secure.

  • How to download a single file from abs cvs (community)?

    As a little edit of soloport's ingenious script for downloading single packages/directories from ABS instead of downloading everything, this is absget.
    #!/bin/bash
    # Downloads a single package from CVS CURRENT (much like ABS)
    # Requires one or two arguments, one which specifes the CVS path (e.g. kernels/kernel26)
    # and the other who specifies the repository (defaults to "arch")
    # Creates a local DIR, for example, where DIR=kernel26 in kernels/kernel26
    if [ "$BASH_ARGC" ]; then
    [ "$2" ] && REPOS="$2" || REPOS="arch"
    export CVSROOT=:pserver:anonymous:[email protected]:/home/cvs-$REPOS
    DIR="$1"
    declare -a ARY
    declare -i NUM
    ARY=( `echo $DIR | sed 's/// /g'` )
    NUM=${#ARY[*]}-1
    PKG=${ARY[$NUM]}
    echo DIR="$DIR", PKG="$PKG", REPOS="$REPOS"
    [ "$REPOS" = "arch" ] && cvs -z3 co -r CURRENT -d $PKG arch/build/$DIR
    [ "$REPOS" = "extra" ] && cvs -z3 co -r CURRENT -d $PKG extra/$DIR
    [ "$REPOS" = "unstable" ] && cvs -z3 co -r CURRENT -d $PKG unstable/$DIR
    rm CVS CVSROOT -R 2>/dev/null
    exit 0
    else
    echo "not enough arguments"
    exit 1
    fi
    As you maybe can see, it's missing a line for community. Whenever I try to test this method with the community dir (/home/cvs-community) I get this error:
    $ export CVSROOT=:pserver:anonymous:[email protected]:/home/cvs-community
    $ cvs -z3 co .
    no such user anonymous in CVSROOT/passwd
    cvs seems to authenticate in a different way than cvsup does, I've tried for hours to get this working (even with the help of wireshark), but with no luck. Can anyone help?

    byte wrote:This could be a hint: http://cvs.archlinux.org/cgi-bin/viewcv … vsroot=AUR (not "Community")
    yes, but I don't know how  to access it without using abs or viewcvs

  • How to download attachments excel file from gmail

    hi,
    i cant able to download attachments from gmail.com, ly i can able to view. can anyone explain how to download attachments from mail.
    rgds
    pravin

    You can't download attachments with an email account via webmail access using a browser.
    You can view attachments in a received email when accessing the account with the iPhone's Mail app and you can save photo attachments to the iPhone's Camera Roll and save PDF attachments to the iBooks app, but all other attachments such as a Word or Excel document can be viewed only.

  • How to Download a PDF file from Webdynpro ABAP Screen

    Hi,
    I have developed a input form in webdynpro - ABAP(Not Adobe),
    As I am not using above services here, but would like to download the information I am capturing into a PDF file.
    can I do it without using adobe interactive forms ?
    thanks
    Siddharth

    Hi siddharth,
    My suggestion would be to create your output as a Smartform and call your Smartform in your View.
    For more Click this link.
    [HOW TO DISPLAY A SMARTFORM AS PDF DOCUMENT IN WEB DYNPRO FOR ABAP|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f0de1eb8-0b98-2910-7996-8a3c2fcf6785]
    Regards
    Bulent

  • How to download a jpeg file from a webpage, daily, automatically

    Hello,
    do you know any app or Automator script that allows me to download an image from a webpage, everyday at the same hour, and without doing any action?
    I need that the Mac will do it automatically.
    Thanks.

    Well, first it would depend on DRM protection (copyrights of the author) whether you can legally download it at all.
    Aside from that, you would also have to automate your Mac to be on that very specific website, connected to the internet, with the mouse choosing which specific image you want to download (as websites can contain many images).

  • Hi i am trying to download a .xls file from server but i cant

    I am using Tomcat 5.0, Where i am trying to download a .xls file.. which was uploaded by me.. when i try to download the file using line.. the content of the jsp file is there in the .xls file, i cant get the original .xls file
    here my code.. i am request this page by a button click...
    browser ask me to save download.jsp file....
    how to download a .xls file from the server... the file was uploaded by me to a folder temp
    <%@ page
    contentType="application/vnd.msexcel; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"
    %>
    <jsp:include page="http://localhost:9999/temp/B.xls"/>

    Help me please, I have this:
    File ficheroXLS = new File(strPathXLS);
    FacesContext ctx = FacesContext.getCurrentInstance();
    if (!ctx.getResponseComplete()) {
    String fileName = ficheroXLS.getName();
    String contentType = "application/vnd.msexcel";
    HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
    response.setContentType(contentType);
    response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
    ServletOutputStream out = response.getOutputStream();
    out.write({color:#ff0000}ficheroXLS.toString().getBytes(){color});
    out.flush();
    out.close();
    ctx.responseComplete();
    My
    problem is marked with red color, I have a file. XLS and I want to
    download it, but to put what this red just showed me the PATH ...
    How can I do to make the contents of this file?
    What type of object must be the xlsReport?
    thanks greetings

  • Download video clip file from website, i.e., YouTube

    Can someone advise how to download video clip file from website & play it back on computer.

    YouTube video clips are flash videos. I use videobox, its shareware, with a free trial, it works for 5 days. Here's the link: http://www.tastyapps.com/ . Did this help?

  • I downloaded a word file from an inbox mail (the mail app) onto my iPad2, where is this file stored? How can I delete it if it takes up space in my iPad? Any ideas??

    I downloaded a word file from an inbox mail (the mail app) onto my iPad, where is this file stored? How can I delete it if it takes up space in my iPad? Any ideas??

    Did you ever figure out what happened?
    I had the same experience as you did, but in my case it was a big fat pdf that Mail insisted I had to download before I could view it. As happened with you, I saw the file actually downloading, and after a time I was able to view the pdf. It's been my assumption that the pdf is still somewhere on my iPad, but I have no idea where, nor how to delete it if it is still there.
    Thanks.

  • I downloaded an Adobe file from my email but cannot find it on my hard drive or in recycle bin - it's in downloads but am unable to open from downloads - how can I recover the file?

    I downloaded an Adobe file from my email (service provider is MWeb) but now cannot find it on my hard drive and it's not in the recycle bin. It does, however, appear in Firefox downloads but I'm unable to open it from there. How can I recover the file?

    Thanks Rob.
    I actually had no clue what the core problem was caused by. So it's Windows itself...that helps some.
    I'll resubmit there. It might actually have saved time for it to simply have been moved to there instead of off-topic, though I suppose you have to follow protocol.

Maybe you are looking for

  • HTTPs connection from SAP WebAS

    Hello, I have to establish a connection from SAP WebAS to an iSaSiLk server via HTTPS. The iSaSiLk authentication is based on client certificates. I've created a SSL client PSE, generated the Certificate Request, imported the certificate response and

  • HT2513 Cannot Create New Events in iCal

    Hello: I recently deleted a large number of appointments from my iCal using my MacBook. Now, iCal on the MacBook will not allow me to see new events I want to create, but it will push the new events to my other devices using iCloud. What's going on?

  • 10.5.7 aiport express problems resolved - so far :)

    Hello all, Since updating my OS to 10.5.7 I have been experiencing frequents drop-outs when trying to stream music through Airtunes from my computers (duocore2 MacBook and 1st gen. intel iMac) to my Airport Express (G). I have past the last 2 days re

  • XML data file import

    1. I exported data using SQL Developer 3.1 in XML format. 2. I get 'No reader of xml type registered' error when I try to import the same XML data file using SQL Developer 3.1. The 'file open' dialog does have an option to pick XML files and it shows

  • Configure SSL Throughout Portal in 10.1.2.0.2

    My installation is going to contain both the Infrastructure (IM, SSO) as well as the Middle-tier (Portal) and I want to later configure SSL. Oracle says in the documentation that the servername must be different for each home. I'm thinking that I wil