+ Reply to Thread
Results 1 to 9 of 9

Perform Action Without Switching To Sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    05-09-2012
    Location
    USA
    MS-Off Ver
    2019 16.0.13205.200000 64-bit
    Posts
    61

    Perform Action Without Switching To Sheet

    Guys, I need to perform an action that would collapse an outline on another sheet. BUT I need to run it WITHOUT switching to that sheet.
    The code I have for this now is the following:
    Private Sub Chart_Activate()
        Sheets("A. Data Sheet").Select
        ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=2
        Sheets("B. Graph Sheet").Select
        ActiveChart.ChartArea.Select
    End Sub
    So it basically switches to that other sheet, collapses the outline and switches back. Is it possible to run this same thing without changing sheets?
    (the reason is that I have a Worksheet_Activate on my data sheet)
    Office 2019 16.0.13205.200000 64-bit

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Perform Action Without Switching To Sheet

    Change "Graph1" to suite
    Sub test()
        Run Sheets("Graph1").CodeName & ".Chart_Activate"
    End Sub

  3. #3
    Registered User
    Join Date
    05-09-2012
    Location
    USA
    MS-Off Ver
    2019 16.0.13205.200000 64-bit
    Posts
    61

    Re: Perform Action Without Switching To Sheet

    Quote Originally Posted by jindon View Post
    Change "Graph1" to suite
    Sub test()
        Run Sheets("Graph1").CodeName & ".Chart_Activate"
    End Sub
    Thanks so much for the answer! However, the thing is that I need to run my macro as Chart_Activate, meaning it MUST be run when users switches to that sheet. Or am I missing something here?

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Perform Action Without Switching To Sheet

    ??
    Then what's wrong with "Chart_Activate"?

  5. #5
    Registered User
    Join Date
    05-09-2012
    Location
    USA
    MS-Off Ver
    2019 16.0.13205.200000 64-bit
    Posts
    61

    Re: Perform Action Without Switching To Sheet

    Quote Originally Posted by jindon View Post
    ??
    Then what's wrong with "Chart_Activate"?
    As I said before on Data Sheet I already have a Worksheet_Activate events that expands the outline when you switch to a sheet. So on graph sheet I have a macro that collapses the data based on Data Sheet and they're conflicting. Again:
    1. on Data Sheet: I have a Worksheet_Activate macro that collapses the data when users switches to it
    2. on Graph Sheet: I need to have a Chart_Activate that would expand data based on Data Sheet, but it must be done WITHOUT switching to it because that triggers #1

    Is that clear enough?

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Perform Action Without Switching To Sheet

    Do you want to update chart sheet after the process of "Activeate" Event?
    If so, add following line at the end of "Activate" code
       Run Sheets("Graph1").CodeName & ".Chart_Activate"
    Is this what you mean?

  7. #7
    Registered User
    Join Date
    05-09-2012
    Location
    USA
    MS-Off Ver
    2019 16.0.13205.200000 64-bit
    Posts
    61

    Re: Perform Action Without Switching To Sheet

    Quote Originally Posted by jindon View Post
    Do you want to update chart sheet after the process of "Activeate" Event?
    If so, add following line at the end of "Activate" code
       Run Sheets("Graph1").CodeName & ".Chart_Activate"
    Is this what you mean?
    I'm not sure I'm following you :/ I mean, the only thing I need to do, is to run this:
    Private Sub Chart_Activate()
        Sheets("A. Data Sheet").Select
        ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=2
        Sheets("B. Graph Sheet").Select
        ActiveChart.ChartArea.Select
    End Sub
    WITHOUT physically switching to "B. Graph Sheet" (because that triggers Workbook_Activate event on that "B. Graph Sheet" and I need to avoid it). If you need any more details, please do ask, I would be happy to provide more info.
    Last edited by splendidus; 06-18-2012 at 07:10 AM.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Perform Action Without Switching To Sheet

    Select triggers Activate event
    Either add
    Private Sub Chart_Activate()
        Application.EnableEvents = Fase
        Sheets("A. Data Sheet").Select
        ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=2
        Sheets("B. Graph Sheet").Select
        ActiveChart.ChartArea.Select
        Application.EnableEvents = True
    End Sub
    Or no Select/Activate
    Private Sub Chart_Activate()
        Sheets("A. Data Sheet").Outline.ShowLevels RowLevels:=0, ColumnLevels:=2
    End Sub

  9. #9
    Registered User
    Join Date
    05-09-2012
    Location
    USA
    MS-Off Ver
    2019 16.0.13205.200000 64-bit
    Posts
    61

    Re: Perform Action Without Switching To Sheet

    Quote Originally Posted by jindon View Post
    Select triggers Activate event
    Either add
    Private Sub Chart_Activate()
        Application.EnableEvents = Fase
        Sheets("A. Data Sheet").Select
        ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=2
        Sheets("B. Graph Sheet").Select
        ActiveChart.ChartArea.Select
        Application.EnableEvents = True
    End Sub
    Or no Select/Activate
    Private Sub Chart_Activate()
        Sheets("A. Data Sheet").Outline.ShowLevels RowLevels:=0, ColumnLevels:=2
    End Sub
    I've just tried option 2, and it worked like a charm! Thank you so very much! I am most, most obliged! : ))))))

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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