+ Reply to Thread
Results 1 to 5 of 5

Let VBA Code Run when using other Office Programs

Hybrid View

  1. #1
    Registered User
    Join Date
    10-11-2015
    Location
    Omaha, NE
    MS-Off Ver
    Microsoft Starter 2010
    Posts
    35

    Question Let VBA Code Run when using other Office Programs

    Not long ago, I had gotten a solution to allow for a Query Table to be refreshed. Since then, I have found a problem that needs to be fixed. Here is the code I have right now:

    Module Code:
    Option Explicit
    
    Dim DataTable As New Class1
    
    Sub Auto_Open()
    
    ActiveSheet.Range("B2").Select
    Set DataTable.qt = ThisWorkbook.Sheets("Data").QueryTables(1)
    End Sub
    
    Sub AutoSort()
    Dim WQ As Range
    Dim wd As Worksheet
    
    Set wd = ActiveWorkbook.Sheets("Data")
    Set WQ = wd.Range("BP2:Bw40")
    WQ.Sort Key1:=wd.Range("BP2"), Order1:=xlAscending, Header:=xlYes
    
    
    End Sub
    Class Code:
    Option Explicit
    
    Public WithEvents qt As QueryTable
    
    Private Sub qt_AfterRefresh(ByVal Success As Boolean)
    
    If Success = True Then
    
    Call Module1.AutoSort
    
    End If
    
    End Sub
    My problem is with the 'Set wd = ActiveWorkbook.Sheets("Data")' part of the code. As long as the workbook Runescape Guide is active, nothing wrong happens. However, when I am using another Office Document at time of Query Refresh, it stops working. Is there a code that can be added to let macro run while the workbook is inactive?

  2. #2
    Valued Forum Contributor
    Join Date
    05-14-2012
    Location
    Unknown
    MS-Off Ver
    Unseen
    Posts
    429

    Re: Let VBA Code Run when using other Office Programs

    ActiveWorkbook refers to the workbook that is selected/active. ThisWorkbook always refers to the workbook where the macro was loaded from.

  3. #3
    Forum Contributor
    Join Date
    09-03-2015
    Location
    IE
    MS-Off Ver
    2003 - 2016
    Posts
    258

    Re: Let VBA Code Run when using other Office Programs

    Ignore - didn't fully read above.

    Re below... I acknowledged that (before you posted ) - I just skimmed your post and didn't take in the 2nd comment.
    Last edited by grimes0332; 02-17-2016 at 05:16 AM.

  4. #4
    Valued Forum Contributor
    Join Date
    05-14-2012
    Location
    Unknown
    MS-Off Ver
    Unseen
    Posts
    429

    Re: Let VBA Code Run when using other Office Programs

    What we both mean is that this
    Set wd = ActiveWorkbook.Sheets("Data")
    should be this
    Set wd = ThisWorkbook.Sheets("Data")

  5. #5
    Valued Forum Contributor
    Join Date
    05-14-2012
    Location
    Unknown
    MS-Off Ver
    Unseen
    Posts
    429

    Re: Let VBA Code Run when using other Office Programs

    @grimes0332: I think I pretty much said that a while back

+ 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. Moving from Office 2003 to Office 2013 - code no longer works
    By GeorgeC47 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-27-2014, 11:20 AM
  2. [SOLVED] How do i change a VBA code complied on office 2007 Bit 32 to Office 2010 Bit 64
    By nathandavies in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2014, 12:17 PM
  3. Recommendations on Fuzzy Matching programs/code?
    By smohyee in forum Excel General
    Replies: 3
    Last Post: 07-07-2014, 02:44 PM
  4. Can excel talk to non MS-Office programs?
    By nimbus3000 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-10-2013, 03:45 AM
  5. send data between other office programs?
    By Pyrex238 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 07-16-2007, 01:06 PM
  6. [SOLVED] Macros across office programs...
    By Kat in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-17-2006, 03:35 AM
  7. [SOLVED] Excel Programs developed in Office 2000 on Windows 2000
    By Trooper in forum Excel General
    Replies: 4
    Last Post: 03-12-2005, 08:06 PM

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