+ Reply to Thread
Results 1 to 3 of 3

Syntax to call a specific workbook and specific worksheet using VBA?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Syntax to call a specific workbook and specific worksheet using VBA?

    Sub main0()
        Dim wb As Excel.Application
        Dim ws As Worksheet
    
        Set wb = GetObject(, "excel.application")
        Set ws = Worksheets("blue")
        
        'wb.Visible = True
        'ws.Activate
        'Range("A1").Select
    
        wb.ws.rng.Select
    End Sub
    Is it possible in VBA to combine the 3 lines

        'wb.Visible = True
        'ws.Activate
        'Range("A1").Select
    into the following line?

        wb.ws.rng.Select
    Basically this is to simplify the room the code takes up. Any help is appreciated.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Syntax to call a specific workbook and specific worksheet using VBA?

    no-unless the workbook and range are active you cannot select a range on that sheet
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Syntax to call a specific workbook and specific worksheet using VBA?

    What exactly are you trying to do?

    Is there a workbook open when you run this code?

    If there was you could use something like this which wil goto A1 on the worksheet Blue in the first workbook
    Sub main0()
    
        Dim wb As Excel.Application
        Dim ws As Worksheet
    
        Set wb = GetObject(, "excel.application")
    
        wb.Goto wb.Workbooks(1).Worksheets("blue").Range("A1")
        
    End Sub
    If posting code please use code tags, see here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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