+ Reply to Thread
Results 1 to 3 of 3

can't activate open workbook based on cell value

Hybrid View

  1. #1
    Registered User
    Join Date
    06-05-2009
    Location
    Charlotte
    MS-Off Ver
    Excel 2007
    Posts
    19

    can't activate open workbook based on cell value

    I have a spreadsheet that opens an excel file based on the value in a given cell. This works fine. However, I need to pass data from my form to this newly opened file. I can't seem to get this file to become the active workbook so I can complete my paste action. I mind you, the file is already open...so I'm rather puzzled why this isn't working. I have to call the file based on a variable, as the file names always change.


    sub macro23()
    
    Windows("Recon Builder Beta2.xls").Activate
    Sheets("Purchase Recon").Select
     Range("L3:L4").copy
     
         purchfile = Range("k1").Value
        
        Windows.Activate Filename:=purchfile
        Sheets("Recon").Select
     
        Range("L3:L4").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    
    end sub
    Thanks, JS

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: can't activate open workbook based on cell value

    You shouldn't have to activate the workbook to copy or paste the data, as long as it's already open. Perhaps try:
    Sub macro23()
    purchfile = Workbooks("Recon Builder Beta2.xls").Sheets("Purchase Recon").Range("K1").Value
    Workbooks("Recon Builder Beta2.xls").Sheets("Purchase Recon").Range("L3:L4").Copy
    Workbooks(purchfile).Sheets("Recon").Range("L3:L4").PasteSpecial Paste:=xlPasteValues
    End Sub

  3. #3
    Registered User
    Join Date
    06-05-2009
    Location
    Charlotte
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: can't activate open workbook based on cell value

    Thanks. Even that gets stuck at the same place, the paste function. It's selecting the range from the first workbook and doing the copy. But then it goes to debug mode when it goes to the line where the paste is, samething as with my original code.

+ 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