+ Reply to Thread
Results 1 to 4 of 4

power query

Hybrid View

  1. #1
    Registered User
    Join Date
    03-31-2016
    Location
    U.S
    MS-Off Ver
    2013
    Posts
    32

    power query

    I need help with some code, i am using power query on a worksheet that is protected and the workbook is protected as well, i am traying to write a code that will refresh the power query for new information and i have this:
    Private Sub CommandButton2_Click()
    
    ActiveWorkbook.Unprotect Password:="Aerogroup"
        
        Sheets("4").Unprotect Password:="abc"
    
    Range("A2").Select
     ActiveWorkbook.RefreshAll
    
    ActiveWorkbook.Protect Password:="Aerogroup"
        
        Sheets("4").Protect Password:="abc"
    
    End Sub
    this dirent work because it say that the workbook is protected and cant refresh the power query table, so i did this:

    Private Sub CommandButton2_Click()
    
    ActiveWorkbook.Unprotect Password:="Aerogroup"
        
        Sheets("4").Unprotect Password:="abc"
    
    Range("A2").Select
     ActiveWorkbook.RefreshAll
    
    If Application.Wait(Now + TimeValue("0:00:10")) Then
     MsgBox "Actualizado"
    End If
    
    ActiveWorkbook.Protect Password:="Aerogroup"
        
        Sheets("4").Protect Password:="abc"
    
    End Sub
    this also did not work, it run the 10 sec showed the msgbox and then again the "cant refresh this workbook is protected".
    anyone has a solution to this please?

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: power query

    Maybe it's just the order of protection:


    Sheets("4").Protect Password:="abc"
    
    ActiveWorkbook.Protect Password:="Aerogroup"
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: power query

    Hi,

    I believe you can add this after the line to refresh the queries:
     Application.CalculateUntilAsyncQueriesDone
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  4. #4
    Registered User
    Join Date
    03-31-2016
    Location
    U.S
    MS-Off Ver
    2013
    Posts
    32

    Re: power query

    ActiveWorkbook.Unprotect Password:="Aerogroup"
        
        Sheets("4").Unprotect Password:="abc"
    
    Range("A2").Select
     ActiveWorkbook.RefreshAll
      Application.CalculateUntilAsyncQueriesDone
     
    ActiveWorkbook.Protect Password:="Aerogroup"
        
        Sheets("4").Protect Password:="abc"
    this worked perfect, thank you.

+ 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. is it possible to incorporate VBA into Power Query ?
    By Hassan1977 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-10-2016, 05:33 AM
  2. Power Query setup
    By chadjh in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 05-05-2016, 11:02 PM
  3. VBA and Power Query
    By Brawnystaff in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-16-2015, 05:10 AM
  4. Power Query TNS Settings
    By Nerdio in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-26-2015, 08:24 AM
  5. power point query
    By jrmehta in forum Excel General
    Replies: 1
    Last Post: 10-11-2010, 01:58 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