Results 1 to 6 of 6

Assigning variable to open workbook

Threaded View

  1. #1
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    Thumbs up Assigning variable to open workbook

    Hello

    I want to create a report that pulls in data from a shared workbook containing multiple worksheets.
    Unfortunately I'm stumbling fairly early as I can't set the variable to refer back to the original file containing the data once it has been opened. Basically I need to be able to toggle between two workbooks but the name of one will vary every time it is used to create the report. Code is as follows:


    Sub ReportMacro()
    Dim fNameAndPath As Variant
    Dim THISWB As Workbook
    
    'Step 1
    
    fNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLS), *.XLS", Title:="Select File To Be Opened")
    If fNameAndPath = False Then Exit Sub
    Workbooks.Open Filename:=fNameAndPath
    
    Set THISWB = ActiveWorkbook
    
    On Error Resume Next
    
    
    Dim WB As Workbook
    WB = "FSD BAS report test.xls"
    
    '
        Windows(THISWB).Activate
        Sheets("Core Input").Select
        Range("I8").Select
        Application.CutCopyMode = False
        Selection.Copy
       
        Windows(WB).Activate
        Range("A3").Select
       
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        
        Windows(THISWB).Select

    Works OK to this point but doesn't go back to file opened at step 1 above but stays in current as this is now deemed to be the active workbook


    Thanks in anticipation
    Last edited by DavidBW; 07-21-2011 at 08:28 AM. Reason: code tags

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