Results 1 to 7 of 7

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

Threaded 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

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

    I am a new member to the forum. I've looked through the various threads, but can't find a solution to my current problem. I have a query in one workbook that updates from a table in another password protected workbook. A password is required both to open and modify the workbook. I need VBA code to open the password protected workbook, update the query, and then close the workbook, after the query has refreshed.

    I have got as far as opening the workbook and refreshing the query. The two areas I need help with are:

    1. what is the code to get past the modify password?

    2. what is the code to close the workbook only after the query has refreshed? (I can close the workbook, but it does it before the refresh is complete and the refresh therefore fails)

    Obviously I have access to all passwords.

    Code extract

    Dim cn As WorkbookConnection
     
    Dim Pass As Variant, wb1 As Workbook
    
    PathName = Workbooks("File").Sheets("Sheet").Range("name")
    Filename = Workbooks("File").Sheets("Sheet").Range("name")
    Pass = Workbooks("File").Sheets("Sheet").Range("name")
    
    On Error Resume Next
    Set wb1 = Application.Workbooks(Filename)
    If wb1 Is Nothing Then
        Workbooks.Open Filename:=PathName & Filename, Password:=Pass
        Set wb1 = Application.Workbooks(Filename)
    End If
    wb1.Activate
     
        For Each cn In ThisWorkbook.Connections
            If cn = "Query - DataList" Then cn.Refresh
        Next cn
    Last edited by MrChipper; 06-09-2017 at 04:39 AM.

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