+ Reply to Thread
Results 1 to 3 of 3

Thread: Make newly opened workbook the active workbook

  1. #1
    Forum Guru
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Excel 2010
    Posts
    1,502

    Make newly opened workbook the active workbook

    My code below is giving me a problem. The first line works, to open the workbook. My second line, the "Set" line, gives me an error cod 424, "Object Required". I think (maybe) it's becuase the workbook newly opened isn't the active workbook, so how do I resolve this? As you can see, I just want it open long enough to copy one sheet from it. Any help is greatly appreciated.
    Thanks,
    John
    Workbooks.Open ("\\12AUST1001FS01\SHARE10011\Budget\SOBUDGET\11MFR\SO_Projections\" & MO & "\" & MO & "_AgyProjections_PivotsforAnalysis.xls"), ReadOnly:=True, UpdateLinks:=True
         Set PivAnal = Active.Workbook
       
       With PivAnal
            .Sheets(Array("Play")).Copy _
                Before:=Workbooks("2BDeleted.xls").Sheets("Lookups")
        End With
        
        PivAnal.Close False
    Last edited by jomili; 05-17-2011 at 10:12 AM.

  2. #2
    Forum Guru Domski's Avatar
    Join Date
    12-14-2009
    MS-Off Ver
    What does it matter?
    Posts
    3,933

    Re: Make newly opened workbook the active workbook

    You can just do this:

    Dim PivAnal As Workbook
    
    Set PivAnal = Workbooks.Open("\\12AUST1001FS01\SHARE10011\Budget\SOBUDGET\11MFR\SO_Projections\" & _
        MO & "\" & MO & "_AgyProjections_PivotsforAnalysis.xls", ReadOnly:=True, UpdateLinks:=True)

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Forum Guru
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Excel 2010
    Posts
    1,502

    Re: Make newly opened workbook the active workbook

    Thanks Dom,
    That's certainly more elegant than the way I was working toward. I had a little trouble at first (parenthesis in the wrong place, my error) but very quickly got that straitened out and the code worked like a champ. I'll use this routine over and over again. Thanks.

+ 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.2.0