Copy Code To New Workbook
Oct 13, 2007
I am trying to paste some codes to the "ThisWorkbook" section of a file. The codes I am trying to paste will prevent the user from: doing a Save As (to keep them from saving the files anywhere else in the network) and to Disable the Macro (only showing a prompt sheet if they do so they can go back and enable the macros). The file that these codes will go to is sheet and workbook protected, and some cells are protected, and cells that they can edit have data validation formulas. In a post dated Nov 6, 2003 (thread 16750) I found a useful code that lets me paste the codes above to a target file. But when I save and close the file, the Disable macro does not work.
So I tried long method and pasted the codes into the ThisWorkbook section manually. Save and closed manually. and when I opened the file, the Disable and Enable works. Just as a background, I am a beginner with VB and I can't write my own codes yet, but I try to piece them together from forum answers. I need VB to do this because I have 263 individual files to prepare. I used to use AutoPilot, which is a scripting software but it's so prone to bonking out that I would rather do it in VB if possible. These are the codes am trying to paste:
Private Sub Workbook_BeforeSave _
(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI = True Then Cancel = True
End Sub
Private Sub Sheet_Activate()
Dim oCtrl As Office.CommandBarControl
For Each oCtrl In Application. CommandBars.FindControls(ID:=21)
oCtrl.Enabled = False
Next oCtrl
For Each oCtrl In Application.CommandBars.FindControls(ID:=19)
oCtrl.Enabled = False
Next oCtrl
Application.CellDragAndDrop = False
End Sub...............
View 2 Replies
ADVERTISEMENT
Mar 24, 2014
I've not had much experience with VBA code, other than recording macros and editing them a little. What i would like to do is code a macro to copy the data (text only) of a whole worksheet into a blank worksheet in a different workbook, effectively allowing the user to "upload" the data to a master workbook.
The user will complete data entry into a daily template worksheet containing all formulae to obtain necessary daily data. I would like them to then be able to click a button that runs a macro copying the text data from the daily template to a monthly workbook. I have no problem recording this in a macro and the code for that (no doubt there is a more efficient way) is:
[Code] .....
The monthly workbook will contain 31 sheets (named 1,2,3...31) for the days, and each month will have it's own workbook (named Jan, Feb, Mar...Dec).
The key thing I need is using cells within the daily workbook to determine the month and day used by VBA for the filename and worksheet respectively.
Cell B5 contains the day (eg. 1) and C5 the month (e.g. Jan)
View 8 Replies
View Related
Sep 10, 2006
In a workbook with several worksheets i would like (as part of a backup function) make a copy of one of the worksheets.
The code of the complete project is distributed over a module (module1) and several Microsoft excel objects ("thisWorkbook", but also in a number of the worksheets (e.g. in "sheet3 (Risk Management Plan)").
The backup copy of the worksheet (in this example also containing e.g. the Microsoft excel object "sheet6 (Backup of Risk Management Plan)" should be free of any macro code. this to avoid unintended problems by inexperienced users, but also to keep the file size limited.
Probably it would be possible to copy the worksheet without of copying also the code. Or it would be possible to strip the code only from this particular worksheet without influencing any other code, forms, ... . Or, perhaps, there would even a totally different approach.
I use Windows XP pro Sp2, and Excel 2000 Sp3.
View 7 Replies
View Related
Dec 14, 2007
Can someone help me to get the code to copy an existing workbook, with all the forms and code that exist with it, to a new workbook with the data from the cells, and name the file with a new name?
View 6 Replies
View Related
Apr 24, 2014
I am looking for VBA which will complete my below task.
copy data from active worksheet to closed workbook.Active sheet data should copy below old data of closed workbook.data contain in A to K column of active worksheet.clear copied dataIf I moved both file any folder or drive, path should change automatically. ( something like fpath = current workbook path clworkbook= fpath & closedwbk.xls).
View 6 Replies
View Related
Dec 30, 2011
Here is the code I have:
Windows("2.xlsm").Activate
Sheets("Report_P").Select
Sheets("Report_P").Copy After:=Workbooks("New_report.xlsx").Sheets(9)
2.xlsm is open. it contains a sheet called Report_P New_report.xlsx is open and has 9 existing sheets
Every time this tries to execute I get a "Run time error 1004 Copy Method of Worksheet Failed".
What is wrong with this code? I have an identical line in another macro, the only difference is that there are 5 sheets pre-existing, and that works fine.
View 6 Replies
View Related
Jan 25, 2012
I am using the following code to copy data from multiple workbooks in a folder to one workbook.
Code:
Sub copy_files()
Dim wkb1, wkb2, wkb3 As Workbook
Dim i, lastrow As Integer
[Code]....
What changes are required in the above code to paste the data in different sheets on one workbook.
View 2 Replies
View Related
Feb 19, 2014
I want the code to run when we open excel workbook "TEST" and it should open up all the workbooks one by one in the folder J:ABC and copy cells C2 and C4 values in the A and B columns of TEST workbook.
e.g There are 5 workbooks in the folder J:ABC so when the TEST workbook is opened then the code should run and open 1st workbook and copy values in cells C2 and C4 to it and close the workbook.
The code should run as below:
1st workbook:
C2 value will go in Test workbook B1
C4 value will go in Test workbook A1
Close 1st workbook
2nd workbook:
C2 value will go in Test workbook B2
C4 value will go in Test workbook A2
close 2nd workbook.
3rd workbook:
C2 value will go in Test workbook B3
C4 value will go in Test workbook A3
close 3rd workbook.
and so on It will be going to next rows in A and B columns.
View 2 Replies
View Related
Mar 17, 2014
My workbook stores data related to items that are all tracked by barcodes. Im using the following code (as part of a larger set of code) to copy data from rows 6 on in column D, E & G to K from one workbook to another. The data in F (Item Names) is found using a formula, by matching the barcode data in the corresponding G cell (on the same row) to another sheet (where the barcodes and Item names are stored). When the data has finished copying over and EnableEvents gets turned back on the F column mostly automatically fills itself in from the formula.
The issue I have however is in certain circumstances there are some items that either dont have a barcode, or the barcode is missing. In this case the user types "none" (not case sensitive), which opens a userform allowing the user to type in an Item name that gets entered into the F cell, overwriting the formula. I need to copy this data over separately to the new workbook. Im looking for code to find these records from row 6 on (either by searching for rows where G equals "none", or rows where F has no formula, and then copy the data in F over to the other workbook to the corresponding row number but offset by the number of records already present in the active workbook (currently being calculated by wbReturnDataLastRow).
[Code] .....
wb is the ActiveWorkbook that the data is being copied to
mybook is the workbook that the data is being copied from
View 6 Replies
View Related
Mar 3, 2008
I have a workbook ("CaTr") Sheet1 has data ranging ("B2:I41").
There are about 30 cells values (scattered) which needs to be copied in a workbook "CA_Log" in one single next available row .
As soon as the CaTr.sheet1 is filled I want the operator to click a button to trigger this event. Then the sheet1 in workbook CaTr should be saved as "G3" cell value.
View 14 Replies
View Related
Jan 27, 2009
I use excel 2002 but some of my office are on 97, i want to add a small workbook open event code which works for me but debugs for the others?? The code is basically, go to a tab, on that tab and that range sort..
View 2 Replies
View Related
Aug 1, 2013
My company has files that are already in use. I don't know too many details about how they work, but somehow saving the file will screw it up and my boss has to go back and reset something or other to correct it. Obviously it's connected to some other software somewhere. The code below will block Save and Save-As. BUT how do I get the file to hold onto the code without actually saving the file after the code is added (since the file shouldn't be saved)?
VB:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI = False Then
Cancel = True
[Code].....
View 1 Replies
View Related
Jun 25, 2014
I'm trying to find a way to save a single sheet of an excel workbook and in the same process delete all vba code and shapes from the new single sheet workbook. I was looking around and found this code which does save only the single sheet to a new one sheet workbook but doesn't delete the vba and shape that I have used to assign macros to in the original.
Code:
Sub SaveSheetAsNewBook()
Dim wb As Workbook
Dim InitFileName As String
Dim fileSaveName As String
Dim wshape As Shape
InitFileName = ThisWorkbook.Path & Format(Date, "mm.dd.yy")
[code]....
View 2 Replies
View Related
Jan 14, 2014
The amazing code I saw was from this thread Auto lock cells after data entry when file saved... where the code was made by Jafaar Tribak.
It basically locks cells that have had data inputted into them when the file is saved (with a nice prompt warning of the used cells being locked.
This is Jafaar's file [URL]
And this is my file where I'm trying to make it work in the "Employee data entry" Sheet:
[URL]
And finally this is the file after I tried to copy the code over : [URL]
Trying to make it so that in the employee data entry sheet locks cells after an employee inputs some data into said cells.
I thought that by setting an "inputrange" on the employee data entry sheet the code would track it down automatically but maybe I'm completely wrong. I cant see anything wrong with it (probably because I"m not that good at vba) but I fear I may have left out something really simple!
I seem to disable my other macros when i try to insert this code in (I have a macro that when you click on a cell a calendar pops up so you can click on a day from the calendar rather than typing out the date)
View 9 Replies
View Related
Sep 12, 2006
How is code or functions kept unique to a workbook? for instance i create a few toolbars that are relevant to "work book 1", however when i open another workbook "2" the toolbars do not function properly or are removed by the opening/closing of the work book, similarly other macros seem to struggle with more than one workbbok open at a time.
View 5 Replies
View Related
Mar 26, 2012
Copy data from workbook, open existing workbook, select range and paste. But my copied data is lost.
Sub Select_Copy_Paste()
'
'
Windows("ElektroFunctiesDatabase.xlsm").Activate
Sheets("PowerSupply's").Select
Range("A2:I6").Select
Selection.Copy
[Code] .........
' Here i need to do something to paste data into r.address?
View 4 Replies
View Related
Feb 11, 2010
I m not able to use the standard Excel Paste Special function when I copied a range of cells in another Excel workbook opened in a separate instance of Excel. Instead, Paste Special thinks that I have copied some non-Excel objects and gave me the Paste As options. This is not the case if I open both workbook within the same instance of Excel. Could you share with us if there is a trick to trigger the normal Paste Special options in such situations (without having to invoke Macro procedures)?
View 2 Replies
View Related
Jun 17, 2014
I have been trying to edit a code which previously saved a copy in a new workbook to a specific folder/path. (Additionally it copies and clears some figures, but this is working as it should.)
However I would like the copy to be saved at the same location as the original workbook, regardless of the path the original workbook is saved.
I.e if I need to move the workbook containing the code to a new folder/location, when using the macro, the new copy should be stored in the same folder/location as the original one.
For now it is only saving the copy into "My Documents"
Code:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 16-02-2009 by ceng
'
Sheets("Bunker ROB").Select
Sheets("Bunker ROB").Copy
ActiveWorkbook.SaveAs Filename:= _
ActiveWorkbook.Path & Range("D3"), _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
[Code] ........
View 2 Replies
View Related
Jun 30, 2014
I run a model in Excel that automatically saves my file every xx iterations. After saving the file I want to make a backup of the file. Tried
[Code] .....
but get a permission denied error message.
I don't want to use .SaveAs as it is a huge file that takes a while to save and SaveAs has a tendency to break links that should not be broken..
View 13 Replies
View Related
Aug 21, 2014
I have an open workbook (A) and this is where the code should reside. I want to use VBA to copy the content of an entire worksheet from a closed workbook (B) to an existing worksheet in workbook A. How would you accomplish this?
View 7 Replies
View Related
Feb 7, 2014
I am looking for a code that would copy the data from each worksheet in a given workbook and then paste to just one worksheet within a different workbook. The Sheet names are auto generated when I run this canned report but the naming structure is always the same...the first worksheet is named Repair Details and then the next sheet is named Repair Details_1, the next sheet is named Repair Details_2 and so on for every sheet in workbook. So I would like to copy all of the data(Headers to last cell) and then paste in a worksheet(ex: Master Repair Report.xlsx and the worksheet could be titled Master Repair Details) on a different workbook, then the next sheet would copy from the one under the header to the last record and paste to the same workbook. This process would repeat for every worksheet in the Repair Details Workbook and paste to Master Repair Details worksheet in the Master Repair Report workbook.
View 4 Replies
View Related
Mar 11, 2014
I have 2 workbooks. 1 is where data is entered called wksPB, the other is like a database workbook. The wksPB has data to be feed from column B to F and there is a dropdown.
what im looking to do is, if the combobox value is selected as Decline then it should display a messagebox that reference value in cell B is denied. if combobox value is Agreed then the macro should search the database workbook for the text entered in column b of wksPB and then copy data of C:E of wksPB to H:J of database sheet where that text is found and also the approver name in wksPB C24 to the approver cell of where that text was found. I've reached till finding the text but what I get my head twiting on is how to copy the text from wksPB column B:F to database sheet column H:K. Im attaching the sample workbooks and the code where ive reached till.
[Code] .....
Attached Files
Replacement Records - 2014.xlsx
forum file.xlsm
View 1 Replies
View Related
Aug 12, 2009
I need to copy a range of values (actually two ranges). The ranges are of fixed size. Le't say A2:D20 and E2:H20.
Both workbooks have the exact same layout, and they both have the same named worksheet (in this case it's called Entry). However the actual filename of the source workbook is unknown. I know numerous users have changed the filename of the xls file.
I want to instruct them to open the old and new workbook, and open a third workbook containing the copy macro, they run the macro and it copies the data.
How can I reference a known worksheet name but of an unknown workbook name esp when the source and destination share the worksheet name?
View 3 Replies
View Related
Dec 7, 2012
Here's my macro:
Code:
Sub CopyRow()'
'Copies row to new sheet, highlights it, marks column 'A' as copied.
'
Dim cCell As Range
Set cCell = Selection.Cells(1, 1)
Selection.Copy
Sheets("Sheet2").Select
Rows("2:2").Select
[Code] .....
Is it possible to modify it to paste into a different workbook called c:filesDestination.xlsm, instead of the existing workbook (Source.xlsm)? The destination sheet name is the same (Sheet2). It's OK if both workbooks are open at the same time.
View 2 Replies
View Related
Feb 6, 2013
I have some vba that opens a closed workbook, copies data from a named range and then pastes it to the active workbook.
However, what is happening is that the closed workbook is opened and only part of the data is pasted. What I would prefer to happen is this:
Open the closed workbook-->copy the named range-->paste(append) to next empty cell in column B.
Heres the code that I have got.
Sub Workbook_test()Dim wb As Workbook
Application.ScreenUpdating = False ' turn off the screen updating
Set wb = Workbooks.Open("G:WAREHOUSEPlanningSmartNew Training Plan raining plan.xls", True, True)
[Code]....
View 5 Replies
View Related
Mar 14, 2013
On one workbook I have "column A" that lists serial #'s, one serial number per cell. What I need is to be able to take all the non blank data from that column and copy it to another workbook with all those serial #'s in 1 cell numerically sorted and separated by commas.
View 1 Replies
View Related
Jul 24, 2013
I would like to use a command button to copy a row of data from one workbook to a column in another workbook. The row of data will have different values on a daily basis but will always be B2 through BE2. I would like the copied row of data pasted in the next available column to the left in the other work book.
View 3 Replies
View Related
Sep 17, 2009
I have multiple workbooks ( with unique names) under same folder. Each workbook has "Report-Corn" sheet.
I would like to copy cell "P15" from each (workbook-> report-corn -> P15) and paste to Master.xls workbook -> Sheet 1 one after another which is also located under same folder.
View 9 Replies
View Related
Mar 5, 2014
I have a workbook that has a lot of formulas in it that reference material stored on my local computer.
I need a macro that will copy all 42 tabs in to a new workbook book without all formulas, but saving all the formats have made. This would save me from every other day coping and pasting manually each of the pages.
View 2 Replies
View Related
Feb 11, 2014
I have this nice macro that copies data from another workbook. I want to make it to also add the filename of the workbook (for example data.xlsx) it copies the data from, in a cell on the actual workbook (for example on sheet "Combined", Cell A10). What should I add to my macro?
View 3 Replies
View Related