+ Reply to Thread
Results 1 to 2 of 2

Macro copying from WB to WB

Hybrid View

  1. #1
    Registered User
    Join Date
    02-20-2008
    Posts
    22

    Macro copying from WB to WB

    Hello

    I have a macro that I want to use in 20 different workbooks that gathers data from another excel file that is created daily. Each workbook series name changes monthly.

    So I need to have the macro to work regardless of the workbook name. The problem is I need the macro to know to go to the data daily sheet and back to the Main workbook regardless of the Name. Like a default setting to activate workbbook maybe something like

    Windows("whereever the macro was is activated from to go back ").Activate

    instead of like this in the code

    Windows("Main235 Feb 08 Ver 6.xls").Activate

    the code I have is below


    
    Sub CopyMain workbook()
    '
    ' CopyMain workbook
    '
    ' Keyboard Shortcut: Ctrl+w
    '
        Range("B66").Select
        Workbooks.Open Filename:= _
            "C:\Documents and Settings\datafile22.xls"
        Range("B4:AH51").Select
        Selection.Copy
        Windows("Main235 Feb 08 Ver 6.xls").Activate
        ActiveWindow.WindowState = xlNormal
        Range("B66").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Windows("datafile22.xls").Activate
        ActiveWindow.Close
        Range("A4").Select
        ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
        Sheets("Summary").Select
        Range("A1").Select
    End Sub

  2. #2
    Registered User
    Join Date
    02-20-2008
    Posts
    5
    Try setting the name of the active workbook to a variabe prior to opening the other workbook:

    'set variable to current workbooks name
    currentbook = Application.ThisWorkbook.Name
    
    'open your other workbook and do what you want
    
    'go back to the original book
    Windows(currentbook).Activate

+ 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