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!
Bookmarks