Results 1 to 4 of 4

Macro help switching between files

Threaded View

  1. #1
    Registered User
    Join Date
    01-14-2011
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Macro help switching between files

    Hello,

    I am not good at macros, but I did the record macro, got it to do what I want, however the problem is that it only appears to work under the filename that it was recorded in. Is there a way to switch between files, when the beginning file name will be different?

    Here is what is going on. I will open I file, could be named anything. The macro copies a selection, opens another document, goes to a specific tab, pastes special the data, goes to a pivot tab, refreshes the data.

    The problem is, the macro fails in other files because it looks for the original file I made it in. Is there a way to make it just use the open file?

    heres the code its using:

    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 5/3/2011 by User
    '
    ' Keyboard Shortcut: Ctrl+q
    '
        ChDir "C:\Documents and Settings\User\Desktop"
        Workbooks.Open Filename:= _
            "C:\Documents and Settings\User\Desktop\Department Check.xls"
        Windows("ABCD123.xls").Activate
            Range("E18:F500").Select
        Selection.Copy
        Windows("Department Check.xls").Activate
        Sheets("From Journal").Select
        Range("A3").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheets("Pivot").Select
        Range("B5").Select
        Application.CutCopyMode = False
        ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
    End Sub
    Like I said, this all works fine if I am in ABCD123.xls, but if I am in ABCD1234.xls, no luck.

    I need that line of code to just use the current document when the hotkeys are pressed.

    Is this possible?

    Hopefully this is simple!
    Last edited by JSD133; 05-03-2011 at 11:08 AM.

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