Copy Worksheet to another Workbook (unopened)
Solved/Closed
Related:
- Excel vba copy worksheet to another workbook without opening
- Excel reference another workbook without opening - Best answers
- Vba get data from closed workbook without opening - Best answers
- Transfer data from one excel worksheet to another automatically - Guide
- Number to words in excel formula without vba - Guide
- Vba case like - Guide
- How to open vba in excel mac - Guide
- Activeworkbook.worksheets current worksheet ✓ - Excel Forum
1 response
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Apr 2, 2012 at 06:26 PM
Apr 2, 2012 at 06:26 PM
Well you nailed both things. Yes you need a macro and yes the macro would need to open that workbook before it can paste data there
You can get the macro by simply running the macro recorder and record your action of copying data, opening file, pasting data and saving
You can get the macro by simply running the macro recorder and record your action of copying data, opening file, pasting data and saving
Apr 4, 2012 at 12:47 PM
Thank you for pointing me in the right direction. But now I am having a bit of a problem with running the macro. For some reason it isn't executing the code properly when I try to run it with the shortcut key, but it will run if I "Step Into" the code, then click the run button while viewing the macro. Here is the code. Any ideas as to why the shortcut doesn't work?
----------------------------------------------------------------------------
Sub CopyOpenItems()
'
' CopyOpenItems Macro
' Copy open items to sheet.
'
' Keyboard Shortcut: Ctrl+Shift+O
'
Workbooks.Open Filename:="C:\filepath\Tester.xlsx"
Range("A1:M51").Select
Selection.ClearContents
Range("A1").Select
Windows("Sheet.xlsm").Activate
Range("A12:M62").Select
Selection.Copy
Windows("Tester.xlsx").Activate
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWorkbook.Save
Windows("Sheet.xlsm").Activate
End Sub
-------------------------------------------------------------------------------
Thank you for all the help,
Josh
Apr 4, 2012 at 01:30 PM
Apr 4, 2012 at 06:00 PM
Since you have said that workbook and sheet from where the data is being copied is same
in this case you have to make the workbook name "assembled" at run time. In your macro you need
Instead of
this
Here is a little modified version
Apr 4, 2012 at 06:06 PM
I am presuming you have excel 2007 or higher
So in that case, DEVELOPER TAB might be hidden. Make it visible. do Google search for the your version of excel.
If you go to developer tab, you will see a button that says macro. Click on that. Goto options and select the short cut you want to have
Apr 5, 2012 at 03:10 PM
Thank you very much for the assistance with this project. I never knew about the macro recorder function and it is awesome! I decided to use an ActiveX Control Button to activate the copy function. But, just to clear up the shortcut key thing above. I had it in place, but it wouldn't execute the macro properly, whereas running the macro from the code screen would be just fine. Anyways, I evolved the project a bit more since our last discussion. It will now read a name and use in the filepath, then it will check to see if the workbook exists. If it doesn't exist, it creates a workbook and then saves it as a particular file name and copies the information to the workbook. If it does exists, then it copies the information to that workbook. And it saves the workbook. The code is below if you want to check it out.
___________________________________________________________________________
Function FileExists(FullFileName As String) As Boolean
' returns TRUE if the file exists
FileExists = Len(Dir(FullFileName)) > 0
End Function
Sub CopyOpenItems()
'
' CopyOpenItems Macro
' Copy open items to dropbox.
Dim FolderName, ProjectManager As String
If Range("D2") = "John" Then
ProjectManager = "John"
ElseIf Range("D2") = "Lorri" Then
ProjectManager = "Lorri"
ElseIf Range("D2") = "Chris" Then
ProjectManager = "Chris"
End If
FolderName = InputBox("What is the name of the folder in dropbox?")
If FileExists("C:\Users\" & ProjectManager & "\filepath\" & FolderName & "\OpenItems.xlsm") = False Then
Workbooks.Add
Range("A1").Select
ActiveWorkbook.SaveAs Filename:="C:\Users\" & ProjectManager & "\filepath\" & FolderName & "\OpenItems.xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
' Application.Goto Reference:="SaveAs"
Else
Workbooks.Open Filename:="C:\Users\" & ProjectManager & "\filepath\" & FolderName & "\OpenItems.xlsm"
End If
Range("A1").Select
Range("A1:M51").ClearContents
Windows("Projects.xlsm").Activate
' Application.CutCopyMode = False
Range("A12:M62").Select
Selection.Copy
Windows("OpenItems.xlsm").Activate
Range("A1").PasteSpecial
Application.CutCopyMode = False
ActiveWorkbook.Save
Windows("Projects.xlsm").Activate
End Sub
_________________________________________________________________________
My next project for this is to take that information that I had copied to the other workbook, and copy it to a master sheet within the original workbook, if certain criteria are met.
If this thread can be marked as solved, then I would appreciate it.
Thank you very much,
Josh