Copy "ThisWorkbook" From One File To Another
Feb 27, 2009
I am trying to figure out the correct way to copy the "ThisWorkbook" module from one file to another. I have looked at Chip Pearson's website page on the topic but am still confused. If its only this one component that you wish to take to the new file.
View 9 Replies
ADVERTISEMENT
Dec 9, 2009
I'm trying to copy all the sheets into a new workbook but the following code does not copy the workbook object called "ThisWorkbook", it does copy ALL the other sheets however.....
ActiveWorkbook.Sheets.Copy after:=Workbooks(fileDst).Sheets(1)
The "ThisWorkbook" object appears at the end of the list names "Microsoft Excel Object" after all the sheets are listed in the VBA project explorer, like this.....
Microsoft Excel Object
<icon> Sheet2(Sheet2)
<icon> Sheet2(Sheet2)
<icon> Sheet2(Sheet2)
<Excel icon> ThisWorkbook
I have code in there that is needed such as Workbook_Open() so it's needed when I copy to a new file or I have to hand copy it everytime.
View 11 Replies
View Related
Jul 3, 2009
I noticed all the code that i have on a userform using activeworkbook will relate to whatever the last active workbook was "who would have guessed hay" Seeing thisworkbook used a lot i decided to go through the whole project and change all activeworkbook too thisworkbook.sheet1 During this i also made a few other changes that i was confident in, When i run it now it errors on the thisworkbook.sheet1.
Is this the wrong way of using thisworkbook to make sure the code always deals with the correct file. (will this ever be affected if the file goes through a Save As)
Or is it during my over conifedents that i have made a error somewhere else and the debuger is point me here cos it hates me.
View 2 Replies
View Related
Apr 29, 2009
I have made a macro that displays a textbox containing the contents of a cell once the cell is clicked. The macro is written in the 'ThisWorkbook' module in the Sub 'Worksheet_SelectionChange'.
Now I want to convert this macro into an add-in so that it works on all the Excel workbooks I open. Is it possible to do this? Or is there a way in which we can automatically put the code in the 'ThisWorkbook' module of any open worksheet (doesn't seem feasible).
If you have any ideas, please let me know?
View 11 Replies
View Related
Nov 5, 2009
I use a code in ThisWorkbook to always open on sheet 1 when opening up the excel spreadsheet.Is there a code that I could put in to ThisWorkbook that would do a check that the workbook was e.g. "WorkbookA". If it wasn't then the start up code would be cancelled/ignored.The reason for this is that I am copying this workbook whenthe user has entered details in to it and so I do not want this code to run in the saved workbook, that will have a different name.
Workbook A is the master copy or template
View 7 Replies
View Related
Jun 4, 2008
Get a code to take the autofilter of every page within Thisworkbook.
Something like the following (but doesnt work)
Sub FilterOff()
Dim ws As Worksheet
Dim i As Integer
i = 1
For Each ws In ThisWorkbook
Worksheets(i).AutoFilterMode = False
Next ws
End Sub
View 9 Replies
View Related
Apr 25, 2008
I try to unload my Addin, but i got this msg:
Thisworkbook is currently referenced by other workbook and can not be closed
Each time when i want to remove it from the main menue, I have to go to toolbars > customize and remove it.
before it used to be unloaded normally by unchecked the addin from the addin window.
View 9 Replies
View Related
Jan 30, 2007
I do not want ThisWorkBook to close prematurely whenever the specified Activeworkbook is closed without saving because there are other tasks to complete. The Workbook_BeforeClose dun seem to fix it for my case below.
Here’s my situation. I want to copy data from a range of a particular protected sheet in 5 (password-protected) workbooks of a similar format, to 5 worksheets(unprotected) in ThisWorkBook, which is the Master Workbook. The password of the protected sheet is common to the 5 workbooks. The passwords of the 5 workbooks are contained in a sheet in ThisWorkbook. After copying the data from Workbook1 ( 1 of 5), ThisWorkbook are prompted for closure, when Workbook1 is closed without saving. Responding to the prompt to save or not to save, forces ThisWorkbook or MasterWorkbook to break the For-Next loop. By setting Cancel = True in Workbook_BeforeClose, I can stop Thisworkbook from closure, but I will still break the For-Next loop. I have considered the method of copying data from a closed workbook, but I dun think VBA allows copying or referencing a closed workbook which is password protected at workbook and worksheet level.
Here’s my coding :
Sub UpdateMaster()
Dim MasterWB As Workbook
Dim TempWB As Workbook
Dim Source As String
Set MyWB = ThisWorkbook
For i = 1 to 5
Set TempWB = Workbooks.Open (Filename:=WB(i), Password:=password(i) )
TempWB.Sheets("ProtectedSheet").Unprotect Password:="SheetPasswd"
MyWB.Sheets(i).Range(XXX).Value = TempWB.Sheets("ProtectedSheet").Range(YYY)
TempWB.Close False ‘dun want to respond toclose ThisWorkbook else it breaks for-next loop
Next i
Application.Quit.
End Sub
View 9 Replies
View Related
Oct 17, 2003
When in a ThisWorkbook macro, I want to call a sub/macro in a Module. Usually you can just do a CALL MACRO1, and it will find it. But my MACRO1 is Private as I don't the users to be able to do a Tools, Macro, Macros and see it. So I don't want to make it a Public macro. So how do I call the private sub/macro from within ThisWorkbook?
Can I proceed the sub/macro's name with the name of the module, kind of like CALL MODULE1.MACRO1? Or do I have to make it public?
View 9 Replies
View Related
Jun 4, 2009
I'm working on the following
Workbooks.Open Filename:= _
"D:CommondataIBMmainBRANCHBURG-PRODUCTS-BOM-ALUMINUM-UPDATE-" & Ucase(Format(DateAdd("y", 0, Date)), "YYYY-MM-DD")&".XLS"
ChDir "D:CommondataIBMmain"
ActiveWorkbook.SaveAs Filename:= _
"D:CommondataIBMmainBRANCHBURG-PRODUCTS-BOM-ALUMINUM-UPDATE-NAFTA.XLS", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWindow.Close
Date: 2009-06-03
What I'm trying too do is open a file, make an exact copy and save it under a new file name.
My problem is in the date formula the day is not always the same. In the sample case it's 03 at other times the day will change.
is there a way too get this too work irregardles of what the day might be?
View 9 Replies
View Related
Feb 13, 2008
This is a sample of the data with which I am working. I know that a macro can do what I need, but I am only versed in Excel formulas and not that much programming. I need to be able to first sort the data by Column C ("Element Type"), then by Columns E, F, G ("Year", "Month", "Day"). Then, I need to be able to copy all rows that have the same "Element Type" and "Year" to a new file, using the same header from the original spreadsheet on each new spreadsheet - doing this multiple times until the end of the file is reached.
Ideally, the new files would have a strict naming convention: XXXXXX-ZZZZ (YYYY).xls, where the X's are the value of the "COOP Station ID" in Column A, the Z's are the "Element Type" from Column C, and the Y's are the "Year" from Column E. If this theoretical macro were run with the Sample Data file I provided, it should result in the creation of five new workbooks. Is there a way to write a macro to do this, or at least something similar
View 3 Replies
View Related
Dec 15, 2009
I have csv files auto generated (with date stamp in name) and saved in a specific folder everyday. I need to find a macro that will copy the row(s) every day and add to the next empty row in the master excel file. Some days the csv file may have a single row of data and on some other days it may have multiple rows of data to copy and paste.
View 4 Replies
View Related
Aug 3, 2006
I have certain excel file that i want to be able to write a macro in order for it to extract certain information from certain cells on different sheet. In other words, i want cell A2 from each of the three different worksheet i have under different files. And have those data automatically update a master excel or access file whichever might be easier.
View 4 Replies
View Related
Jan 26, 2008
Below is the current code I have for File Copy before the workbook closes. This file will be distributed all over and obviously will not have the same old path and new path locations as I have in my code also will not have the same file name. Is there anyway to still perform the file copy without knowing the old path and file name and possibly have message box pop up to ask the copy to location and use that in the new path string?
Sub Macro1()
Dim fs As Object
Dim oldPath As String, newPath As String
oldPath = "I:EXLDATAMC Daily" '<---Where the file is currently located
newPath = "H:South RegionOrlando Mail Services2008DI" 'Since the super shared drive is super slow we will just copy and replace this file each time before we close and of course after we save
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CopyFile oldPath & "" & "OrlandoMail.xls", newPath & "" & "OrlandoMail.xls"
Set fs = Nothing
End Sub
View 4 Replies
View Related
Jun 26, 2012
I already have code that I believe is supposed to do what I'm trying to accomplish. However, it doesn't fully work. The Macro is below:
VB:
Workbooks.Open Filename:="C:Documents and Settingsplp138DesktopExample 1.xls"
On Error Resume Next
With Workbooks("Example 2.xls")[code]....
Basically, what I'm trying to accomplish is to have a certain range from one file copied, and pasted in the next available (empty) row of another file. While debugging I see that everything is working except for the actual pasting.
View 3 Replies
View Related
Feb 5, 2014
I just found a code to copy file path and file contents. However it is copying folder path and folder contents.here is my requirement.I will specify a path, macro has to copy that file name in a particular cell, then it has to copy all its contents.
ex:
file name 1 has 3 sub files in it, file name 2 has 2 sub files in it--
column AColumn B
file name1file contents
file name1file contents
file name1file contents
file name2file contents
file name2file contents
And also i have extend this macro to write a index function. i will tell u about this. but first i need above thing I researched but I didn't find.
I need file name in a column then i need file contents in b column.
if a file has 10 file contents in a file then that file name should come 10 times in a column, and in b column all its contents.
View 14 Replies
View Related
Mar 11, 2007
Is it possible w/ some vba code to copy the names of files, either from a search or a specific directory to an Excel Worksheet?
View 9 Replies
View Related
Aug 23, 2008
Is there an easy way to automatically copy data from 1 Excel spreadsheet to another when the data is slightly out of order? Currently an admin copies and pastes from file 1 to file 2 manually. There are approximately 800 names to copy. It would be ideal to type a command or press a key and have file 2 updated automatically. Is there a feasible way to accomplish this without spending a lot of money or time?
file 1 file 2
john 100 john 100
june 200 lance 50
marie 150 june 75
stan 100 marie 125
phone 50 stan 200
hold 25
In the example above, if lance doesn't appear in file 1 his amount doesn't get copied and his 50 remains the same. The amounts do not get added, just pasted over from file 1 to file 2 with the days sales results. Only the names on file 2 get pasted over. Phone and hold amounts in file 1 are ignored.
View 3 Replies
View Related
May 13, 2009
if I put my code to Word or Access or PowerPoint, is there some global version of "thisworkbook"? I mean, something like "thisapplication" or something?
View 9 Replies
View Related
Sep 18, 2009
I have an existing spreadsheet with a column of strings (actually VIN numbers). These numbers correllate to a bunch of text files, that can exist in one of three folders (UsernameDesktop1, 2, or 3) on my desktop. What I need the macro to do is:
1) get the filename from A2 (A1 is a heading row)
2) Find the appropriate text file in one of the three folders
3) Put the folder name into I2
4) Scan the text file for some strings, and copy some data that follows those strings into J2:O2 (I can handle programming this)
5) Close the text file
6) repeat above for the remainder of filenames (about 1800 files)
View 3 Replies
View Related
May 11, 2009
after i open the excle file (any file). i need a macro to copy excel filename to A1 cell.
View 3 Replies
View Related
Mar 15, 2014
I have a very large excel file and i want to copy specific rows (ex. 61, 277, 358, 6547, etc) to another excel file.
View 1 Replies
View Related
Jan 3, 2007
I am trying to automate a process that I do manually today. I have a specific folder that contains 4 .csv files. We will call them:
sheet1.csv
sheet2.csv
sheet3.csv
sheet4.csv
They are the only format that ARS Remedy can export in. I wish to copy the contents of these four .csv files to unique tabs in an Excel workbook. The name of each tab should match the name of the .csv file that provided the data. For exmple sheet1 would contain all the data from sheet1.csv and so on... I'm just learning the ropes to VBA and I am running out of time to play around with this.
View 12 Replies
View Related
Oct 8, 2008
Is it possible to press a button in "abc.xls" and have excel ask me which .xls to look in and which rows from that sheet that should be copied and pasted at the bottom of "abc.xls"
Rows to copy would be copied entirely and identified by physical review not by excel looking for a specific value in the row.
View 6 Replies
View Related
Apr 22, 2009
I am trying to copy a text file that is currently open in the workbook directory to another directory. I have been using
View 4 Replies
View Related
Sep 25, 2009
I have two userform one if useing the getopenfilename to popluate a listbox. and then i use these listbox item withen this code to copy the files into a new folder. This works ok.
Then i copy a program into the same folder jpegresize.exe this program makes resized images of all files in its directory. by defult this program should only deal with these files. though what is happening is instead of using the files in the new folder it running on the files where the originals where copied from. (hope that makes sence). Though if i run jpegresize.exe from the new folder or command prompt it. It runs like it should. So i cant figure it out is there somethink the the shell and wait is passing that it shouldnt be.
View 3 Replies
View Related
Jan 30, 2012
from an active workbook, I would like to open a new file "testfile" and copy two work sheets ("result1", "result2") into the new file and then close it and continue working in the active workbook. seems simple but i keep getting errors.
View 2 Replies
View Related
Apr 29, 2008
I need tweaking a new recorded macro, since it is a little bit more complex.... Basically, I want the macro to prompt open a text file then set the parameters for the text import wizard menu (which is where I am now). When it opens, the first row is blank. I want to copy another file's header (row1), lets call it PB Header.xls, to the blank row of the text file. here is the macro so far: ...
View 9 Replies
View Related
May 1, 2009
I have a macro that copies sheets from 4 source files to one master file.
I have a distribution file that has many sheets, each sheet represents a master file. On each sheet, there are four columns A:D, that have lists of sheet names from the 4 source files. The macro scrolls through List A on the first sheet, opens the source file, and copies each tab listed in column A to a new file, it then copies all the sheets listed in column b (from source file #2) to the newly created file and repeats for columns C & D. The new file is saved using the worksheet name on the distribution file. The whole process repeats for each sheet in the distribution file.
Here's the problem, if there are more than 42 sheets being copied to the new file, the macro stops copying them over. I have an on error continue next in the macro, so I don't know if it is erroring out, but when I F8 through, it acts like it's copying the file over, it just doesn't.
The problem does not occur with fewer than 35 sheets being copied.
The most sheets in a workbook would be 60, so I don't think I'm running out of sheet room.
View 9 Replies
View Related
Jan 7, 2010
I need to copy data from File 1 to File 2. I need the macro to copy B5:B14 in file 1 and paste the data in file 2 under Column C. However the row it starts it depends on todays date (which is located in Column A). It would need to find tomorrow date in column A, move over to Column C and paste the data.
How in the heck do you get VBA to look and find the correct date, and paste the data 2 columns over?
View 9 Replies
View Related