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!
Related
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.
I'm trying to import an xlsx worksheet into an xls workbook and ran into an error regarding the number of rows is greater in the xlsx then the xls. I'd like to add a check to the beginning of my macro which detects in the open workbook is xls and then saves as xlsx and re-opens with new format.
I am fairly certain I can do this via checking the "file extension", but I'd feel better utilizing some sort of function built into Excel/VBA which can detect if a file is "Excel 97-2003" style workbook as users can simply change a file extension without changing file type. Is there a way to programmatically check what type of workbook is currently open? ActiveWorkbook.
I don't have any code to share as all I can find is related to checking if file is open, or checking file extension etc etc. Perhaps my google-fu is off today, but I am not getting anything related in my searches so I have tried nothing.
I'd use the Workbook.FileFormat property:
Returns the file format and/or type of the workbook. Read-only XlFileFormat
If ActiveWorkbook.FileFormat = xlExcel8 Then
ActiveWorkbook.SaveAs fileFormat:=xlOpenXMLWorkbook
End If
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
I have macro, using which i am trying to open a excel file then make some validation in the file that is opened. And Open another excel file and put the validation results(of excel file 1) in the form of report in the 2nd Excel.
So the task i have to do here is:
Open Excel file 1
Script to validate data in excel file 1.
Open Excel file 2
Enter the results in it.
Here i am able to open two excel files but not able to create pointers to them. Such as
if i use Sheets("Sheet1").Range("A1").value 'this picks data from Excel file 1.
But to access Excel file 2 what do i need to write, is this something like this:
Sheets("!Sheet1").Range("A1").value
Please help me to fix this. Thanks.
Application.Workbooks("create-a-macro").Worksheets(1).Range("A1").Value = "Hello"
Visit http://www.excel-easy.com/vba/workbook-worksheet-object.html
I want to create a batch file which when I run this file, an excel file should open with some columns in it.
Say if I click on batch file, excel file with columns name, project, ID should also get included in excel file.
Also with this a macro should be open.
Please help. I dont have any idea about this.
I don't think it is possible to automate excel with pure batch.
Why not:
Create an "template" excel file with the default columns and macro included
Have a batch file copy this template (copy template.xslx newfile.xslx) file and open it (`Start newfile.xslx).
For the new file, you'd either have to generate a random or timestamp-based name or have the user enter the name before making a copy.