Save specific sheet to a new workbook using vba - excel

I am working on a vba project. My requirement is, to delete/move a existing sheet from an excel file to a new excel file using vba code. That means to Save specific sheet to a new workbook. I have tried it alot but the file which is being saved is not a new workbook. It is the existing one.
Code is as below :
xlWorkbook.Sheets("Sheet3").Copy -- this line opens sheet3 as a new workbook
xlWorkbook.Sheets("Sheet3").SaveAs "***Path where file is be saved***", FileFormat:=56 -- this line save the original excel file including Sheet1 and Sheet2. But requirement is only having Sheet3.
xlWorkbook.Sheets("Sheet3").Delete -- this line delete the Sheet3 from original as expected.
I can not use any kind of reference file or Excel 12.0 Object library. So
Please if anyone can suggest me or help me. Will appreciate.

Use two lines:
xlWorkbook.Sheets("Sheet3").Copy
xlWorkbook.Application.ActiveWorkbook.SaveAs "***Path where file is be saved***", FileFormat:=56

Related

Copy sheet(s) from one excel file to another excel file

I have an excel sheet that is opened and I want to copy some specific sheets from target excel file into the file that is opened.I want to have
A field to define the path of target excel file.
A field to define the name of the sheets to be copied.
A button to execute the command.
Can someone one give me source code or a place where I can get the help regarding the required functionality or best if there is file with macro.

Workbook contain macro save as new workbook

I have workbook contain macro. The report name is ppAug22.xlsm. Every month I will save new workbook - ppSep22.xlsm containing macro inside the new workbook. I put all the file path and new file name in sheet1 inside ppAug22.xlsm. After I run the macro in ppAug22.xlsm. It only help to save the new file ppSep22.xlsm. Other part macro cannot run. Could anyone have suggestion to solve it?
Regards,
Joe

VbA to save a TXT formated copy of excel sheet

I am trying to make a macro to save data from a sheet of an excel document to a text file.
I am using the following which does produce the file I need:
ActiveWorkbook.SaveAs Filename:="Rate File.txt", FileFormat:=xlTextPrinter
The problem is I want this new saved file to be independent/a new file where it is currently renaming the current excel workbook and treating the new saved file as if it's part of the workbook. So you can't open or use the text file because it says it's open in the excel workbook.
I tried the below code :
ActiveWorkbook.SaveCopyAs Filename:="Rate File.txt", FileFormat:=xlTextPrinter
but get an error because it will not let you format it anymore. The savecopyas part though is making an independent file like I want it to, but makes a file that is just jiberish and can't be used for anything.
Is there a way to save an independent copy but still have it formatted as the txt file type? Thanks!

Copy a sheet from another open workbook into current workbook

I'm trying to write a macro that takes Sheet1 from another, already open, workbook and copy it into a the workbook that will use the data. The macro will be run from the workbook that will be receiving the copied sheet and the file I want the data from will always be named the same.
I've tried the follow code, but it either just copies incorrectly or doesn't work.
Workbooks("FileIWantToCopyFrom.XLSX").Sheets("Sheet1").Copy
ActiveWorkbook.Worksheets("FileIWantToCopyFrom.XLSX").Select
Sheets("Sheet1").Copy After:=Workbooks("Book1").Sheets(1)
Any help would be much appreciated. Thanks!

Excel Copy a sheet with its code to a new xls file

Please, could you tell me if the following is possible in VBA:
I need to write code that copies a sheet from my workbook to a new freshly created xls file. BUT, the sheet I wanna copy has a Macro behind (it's actually a WorkSheet_Change event handler) that I also want to copy to the new file.
Many thanks
Kind regards,
Miloud B
You can Export the code from the original and then Import it into the copy.
Here's an article that shows some code for doing this: Macro to Add a Macro to New Workbooks

Resources