Copy worksheet from one workbook and paste to another - excel

In my macro, I have the user open a workbook due to the name changing every month. I need the first worksheet on this now open workbook to copy and then paste into my original workbook.
I've been trying the below:
ActiveSheet.Copy After:=Workbooks("LTD_LIFE_Macro.xls").Sheets("instructions")
but keep getting an error message.

Related

Create kind of temporary workbook from active workbook and then save temp. wb without changes in act. wb.. Excel VBA

Hello I have a workbook from which I need 2 sheets. The sheet 1 is needed to be copy pasted as values (to eliminate formulas and preserving formatting). MY logic is following :1) create a kind of temporary workbook of the initial file 2) then do copy paste as values 3)select only sheet 1 and 2 4) save this temporary workbook (with two sheets) to the folder. This is done in order to avoid any changes in the active (original ) workbook. I am using the following code and it seems to work. However my initial active workbook is also changed (in the first sheet only values (no formulas)). What should I change in my code , so that my schema starts working.
Set tb = ActiveWorkbook
tb.Sheets(1).Cells.Copy
tb.Sheets(1).Range("A1").PasteSpecial Paste:=xlValues
tb.Sheets(Array("Sheet1", "Sheet2")).Select
tb.Sheets(Array("Sheet1", "Sheet2")).Copy
tb.SaveAs Filename:="C:path"

Open Second Workbook Triggers VBA Code in First Workbook

I open an Excel workbook which has some VBA code in it including Event code on one of the worksheets. I open a second workbook which has no VBA code in it at all but as soon as the second workbook opens, it triggers the VBA code to run in the first workbook. The code fails because the first workbook is not the Active Workbook. Anybody got any ideas why opening a second workbook should trigger event code in the first workbook?
I can replicate that -seems like opening a workbook triggers the calculate event in other open workbooks. Having said that, your event-handling code should not rely on any particular workbook being active when it runs, so it would help to post that if you want suggestions for fixes.
For example the worksheet object which corresponds to the sheet module can be referenced via Me, and the workbook containing that sheet is Me.Parent
Private Sub Worksheet_Calculate()
Debug.print "calculating " & Me.Name & " in " Me.Parent.Name
End Sub

How to copy ActiveWorkbook name to Clipboard?

The macro is supposed to open a new workbook, copy its name, and then use it within the same active workbook.
The MsgBox works just fine but copying this piece of information instead of displaying it gives me a headache.
Thanks!
MsgBox ActiveWorkbook.Name

How to activate the excel from where I run my vba but not by Windows(filename).activate

I have an Excel workbook called Book1 with VBA code that opens another workbook and gets data from it to add it to Book1.
In my code it is written that:
Windows("Book1.xlsm").Activate
When VBA gets back to the workbook where my code is starting, I want to make a reference to my workbook so that it won't matter whether the workbook will be named Book2 or any other name and won't matter where it will be located. How can I do this please?

RENAME Excel worksheets dynamiccaly using VBA

I have about 50 workbooks each with two tabs. I want to rename the first worksheet with the same name that of the workbook name.
I know how to to this when there is only one worksheet tab in the workbook.
But It does not work with multiple tabs.
How can I use VBA to dynamically rename worksheets that is same name as workbook name?
This will rename a worksheet to have the same name as the workbook it is in:
Worksheets(1).Name = ActiveWorkbook.Name
If there are several workbooks and you want to rename the first worksheet in each automatically, you could build a loop around this statement that opens each workbook and then runs the line of code above.

Resources