+ Reply to Thread
Results 1 to 7 of 7

VBA code to update query from a password protected excel workbook and then close workbook

Hybrid View

MrChipper VBA code to update query from... 06-06-2017, 11:08 AM
TMS Re: VBA code to update query... 06-06-2017, 01:35 PM
MrChipper Re: VBA code to update query... 06-09-2017, 04:54 AM
TMS Re: VBA code to update query... 06-09-2017, 05:39 AM
MrChipper Re: VBA code to update query... 06-09-2017, 06:10 AM
MrChipper Re: VBA code to update query... 06-14-2017, 04:57 AM
TMS Re: VBA code to update query... 06-14-2017, 07:41 AM
  1. #1
    Registered User
    Join Date
    06-06-2017
    Location
    Wimborne, England
    MS-Off Ver
    Office 365 Business
    Posts
    30

    Re: VBA code to update query from a password protected excel workbook and then close workb

    I tried the code below as a timer, but all that happened is that, even though this was added after the refresh instruction, the blue circle spun for 5 minutes after the workbook open, then it closed and then it asked me for the passwords, reopened and then did the refresh after which I had to close the workbook manually.

    newHour = Hour(Now())
    newMinute = Minute(Now()) + 5
    newSecond = Second(Now())
    waitTime = TimeSerial(newHour, newMinute, newSecond)
    Application.Wait waitTime
    
    Application.DisplayAlerts = False
    ActiveWindow.Close
    Application.DisplayAlerts = True
    I did wonder whether it had something to do with running the query in background, but when I changed this, the refresh didn't complete.

  2. #2
    Registered User
    Join Date
    06-06-2017
    Location
    Wimborne, England
    MS-Off Ver
    Office 365 Business
    Posts
    30

    Re: VBA code to update query from a password protected excel workbook and then close workb

    Quote Originally Posted by MrChipper View Post
    I tried the code below as a timer, but all that happened is that, even though this was added after the refresh instruction, the blue circle spun for 5 minutes after the workbook open, then it closed and then it asked me for the passwords, reopened and then did the refresh after which I had to close the workbook manually.

    newHour = Hour(Now())
    newMinute = Minute(Now()) + 5
    newSecond = Second(Now())
    waitTime = TimeSerial(newHour, newMinute, newSecond)
    Application.Wait waitTime
    
    Application.DisplayAlerts = False
    ActiveWindow.Close
    Application.DisplayAlerts = True
    I did wonder whether it had something to do with running the query in background, but when I changed this, the refresh didn't complete.

    Ok. The following code worked. I used this Loop to delay the close of the workbook:

    Sub WasteTime(Finish As Long)
    newHour = Hour(Now())
    newMinute = Minute(Now())
    newSecond = Second(Now()) + Finish
    waitTime = TimeSerial(newHour, newMinute, newSecond)
         
        Do
            DoEvents
        Loop Until waitTime <= Time()
     
    End Sub

+ 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] How to run a macro behind a Password Protected excel workbook
    By chrisandsally in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-16-2015, 08:05 AM
  2. [SOLVED] Code to cut cell from one workbook, close same workbook, and paste in different workbook
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 03-13-2014, 04:01 PM
  3. unable to close password protected workbook using VBA code in another workbook
    By abulooz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-04-2012, 08:54 AM
  4. Create Query from Password Protected Workbook
    By Joy C in forum Excel General
    Replies: 0
    Last Post: 03-25-2011, 05:46 AM
  5. Refresh query with a password protected workbook.
    By Joy C in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2011, 12:31 PM
  6. code to update very hidden sheets in a protected workbook
    By Balachan56 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-22-2009, 05:31 PM
  7. Replies: 2
    Last Post: 03-30-2005, 09:06 AM

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