+ Reply to Thread
Results 1 to 5 of 5

Wait For File To Exist Function

  1. #1
    Forum Contributor
    Join Date
    02-20-2017
    Location
    Indiana
    MS-Off Ver
    2016
    Posts
    101

    Wait For File To Exist Function

    Hello,

    My VBA macro runs a VBscript to pull a report from SAP. I need to pause the vba script to account for the time it takes the VBscript to fully run. I was using a function that waits for the file to be saved to my desktop, but this SAP report can't be saved and exported. It can only be exported to excel. So I was thinking of another way of checking to see if the VBscript is done running. That is looping an activate wb function. If the wb activates, then continue the vba script. If the wb doesn't activate, then pause for a couple of seconds and try to activate the wb again.

    The code below waits for the file to exist on my desktop. I'm hoping someone can assist me in editing the code to loop activating the wb instead of checking for the file on my desktop, or point me in the right direction as to what needs edited.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Wait For File To Exist Function

    you probably want to loop through the workbook collection each time

    Please Login or Register  to view this content.
    Although wouldn't it be tidier to change the VBscript to export it to a known location?
    And better yet to do the whole thing either in VBA or the VBscript?
    Or if you have the sap data warehouse (BW/AFO) to use that?

  3. #3
    Forum Contributor
    Join Date
    02-20-2017
    Location
    Indiana
    MS-Off Ver
    2016
    Posts
    101

    Re: Wait For File To Exist Function

    hello and thanks for the response.

    I've heard of translating VBscript to VBA before, but I have no knowledge of how to do that. Also I'm not technically skilled enough to implement the activate wb check.

    But I did think of a way around this obstacle. Instead of just pulling the one report that can't be saved to my desktop, I'm going to change my VBscript to pull that report first followed by a very short report that can be saved to my desktop from SAP.

    Just using the current check I have now will register when I have the second report on my desktop and then proceed with the VBA macro. In a sense, if I have the second report, then I have the first report. Then I'll just kill the file later in the VBA macro.

    This should take an extra 15-30 seconds, but it's the only implementable check I can think of for now.

    I'll leave this thread listed as unsolved incase someone else can think of a more efficient way of doing this.

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Wait For File To Exist Function

    Using a phone so not going to read the code above; or add code to this post, but if i was to wait for a file to exist (and be available for the app), I'd write a little procedure to first check the file exists, then try to open it for input with an exclusive lock. If it can be locked then no other process has the file open.

    That can all be bound up in a loop which will exit if a set time has elapsed... Just a thought, but I'll have a look at the logic of the code you posted a little later, if you want.

  5. #5
    Forum Contributor
    Join Date
    02-20-2017
    Location
    Indiana
    MS-Off Ver
    2016
    Posts
    101

    Re: Wait For File To Exist Function

    Quote Originally Posted by cytop View Post
    I'll have a look at the logic of the code you posted a little later, if you want.
    Sure, thanks for taking a look!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Wait For File To Exist Function
    By BryceVBA in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-21-2017, 12:39 PM
  2. [SOLVED] Wait on File.readonly
    By evertjvr in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-17-2015, 04:32 AM
  3. [SOLVED] Wait for Notepad to open file
    By jimrosser in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-30-2014, 12:56 PM
  4. if file is open - try again, wait, try again
    By papasmurfuo9 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-06-2014, 10:39 AM
  5. Wait for user to open new file
    By bishope in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2013, 03:47 PM
  6. Replies: 3
    Last Post: 03-11-2006, 02:50 PM
  7. Replies: 0
    Last Post: 03-10-2006, 05:55 AM

Tags for this Thread

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.6.0 RC 1