+ Reply to Thread
Results 1 to 6 of 6

Windows Wildcard Activate

Hybrid View

  1. #1
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    Windows Wildcard Activate

    Hi All, I have an issue with the Windows.Activate property.
    I have a macro that vertically splits the view into two windows for the user, and the problem is the specific workbook reference in the syntax.
    Here is what I have so far:
    Sub SplitView()
    ' vertically splits view
    Dim wb1 As Workbook
    Set wb1 = ThisWorkbook
    
    If ActiveWindow.WindowState <> xlMaximized Then
      Exit Sub
    End If
     ActiveWindow.NewWindow
     Application.Windows.Arrange ArrangeStyle:=xlVertical, ActiveWorkbook:=True
     Windows("Workbook1.xlsm:2").Activate
     ThisWorkbook.Worksheets("Sheet1").Range("A15").Select
     ActiveWindow.FreezePanes = True
     Windows("Workbook1.xlsm:1").Activate
     ActiveWindow.SmallScroll ToRight:=16
    The name of this workbook will change and therfore throw up a reference error, so I was wondering if someone could point me in the right direction. I can't quite figure out how to reference wb1 in the Windows.Activate property.

    Thanks!

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Windows Wildcard Activate

    If you open them in a specific order them reference the Index property.
    Workbooks(1).Activate

  3. #3
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: Windows Wildcard Activate

    Thanks pj, thats a good suggestion, but the end user will already have at least one other workbook open before the macro is ran, so the Index number would be variable.

    Thanks

  4. #4
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: Windows Wildcard Activate

    Update:
    Haven't come across a solution so far, so in the meantime I've added a bit of code to exit the sub if the workbook name is changed:
    Sub SplitView()
    ' vertically splits view
    Dim wb1 As Workbook
    Set wb1 = ThisWorkbook
    
    If ActiveWindow.WindowState <> xlMaximized Then ' exits if window is not maximized
      Exit Sub
    End If
    
    If Not wb1.Name Like "Workbook1.xlsm" Then ' exits if book is renamed
    Exit Sub
    End If
    
     ActiveWindow.NewWindow
     Application.Windows.Arrange ArrangeStyle:=xlVertical, ActiveWorkbook:=True ' vertical view
     Windows("Workbook1:2").Activate ' activates window 2
     ThisWorkbook.Worksheets("Sheet1").Range("A15").Select
     ActiveWindow.FreezePanes = True ' freezes header
     ActiveWindow.Zoom = 87 ' resets view for split window
     Windows("Workbook1:1").Activate ' activates window 1
     ActiveWindow.Zoom = 87 ' resets view for split window
     ActiveWindow.SmallScroll ToRight:=16 ' scrolls right so second report is in view
    
    End Sub
    Hopefully a solution is possible, but if not, this way there won't be any errors.

  5. #5
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: Windows Wildcard Activate

    Bumping along.

  6. #6
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: Windows Wildcard Activate

    Update: Ended up finding a solution by using the windows index number. This also solves the problem of having multiple workbooks open, as it will exit the sub if that condition exists

    Sub SplitView()
    ' vertically splits view, set to not work if more than one window is open to include other workbooks
    
    If Windows.count > 1 Then ' exits if windows are more than one (includes open workbooks)
      Exit Sub
    End If
    
     ActiveWindow.NewWindow
     Application.Windows.Arrange ArrangeStyle:=xlVertical, ActiveWorkbook:=True ' vertical view
     Windows(1).Activate ' activates window 2
     ThisWorkbook.Worksheets("Sheet1").Range("A15").Select
     ActiveWindow.FreezePanes = True ' freezes header
     ActiveWindow.Zoom = 87 ' resets view for split window
     Windows(2).Activate ' activates window 1
     ActiveWindow.Zoom = 87 ' resets view for split window
     ActiveWindow.SmallScroll ToRight:=16 ' scrolls right so second report is in view
     
    End Sub
    Marking this as solved.
    Thanks

+ 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] Wildcard text to activate workbooks name
    By Faridwahidi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-03-2014, 02:38 AM
  2. activate and copy open workbook using a wildcard
    By sammar12 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-25-2012, 12:32 PM
  3. Activate Workbook Using Wildcard
    By contra76 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2010, 05:10 PM
  4. Activate worksheet using wildcard
    By contra76 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-25-2010, 02:19 PM
  5. Copy Data between two workbooks (Wildcard windows().Activate)
    By gfishman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-12-2010, 02:20 PM

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