Question : Create File copy of XLS via command line or VBA code

i need to create a process that will copy an excel file, rename and save it to replace existing file.  i need to schedule this task nightly. When I try to do a copy within Excel, I run into the 255 character issue.  So i need to make a copy of the actual file and then rename and save it in the same place every night.

Looking for the best approach to whether I should use VBA within an empty Excel wkbook or use a command line in a shortcut, or use a bat executable to make the copy of the file?

I will also need to exceute code that will format the headers so that it can be saved as .csv file.

thanks,

Karen

Answer : Create File copy of XLS via command line or VBA code

The revision of your question is a little different than the original copy/paste that you started with...

As far as the 255 char limit you might be able to get past that by using variable to represent chunks of data, e.g.

parta = "c:\windows\filefolder\fileforder\"
partb = "otherfolder\anotherfolder\"
partc = parta & partb

You can copy/rename a worksheet by:

Sheets("test2").Copy After:=Sheets("test1")
Sheets("test2").name = "newname"

Copy and save as csv:

ThisWorkbook.Worksheets("test2").Copy
ActiveWorkbook. SaveAs Filename:="C:\path\file.csv", FileFormat:=xlCSVWindows


Run a macro on Open:

Private Sub Workbook_Open()
      Run "YourMacro"
End Sub

Read only / Password:

Workbooks.Open Filename="yourFile.xls", ReadOnly:=True, Password:="yourpassword"

or separate:

Workbooks.Open Filename="yourFile.xls", ReadOnly:=True
Workbooks.Open Filename="yourFile.xls", Password:="yourpassword"

NG,

Random Solutions  
 
programming4us programming4us