View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Arran Arran is offline
external usenet poster
 
Posts: 50
Default Rename Excel File

Hi OssieMac,

Thanks for your help, pointed me in the right direction and came up with the
following code that works perfectly:

Dim OldPath As String
Dim NewName As String

OldPath = NewFormWkbk.Path & "\" & NewFormWkbk.Name

NewName = Left(OldPath, Len(OldPath) - 4) & " - Imported.xls"

ActiveWorkbook.SaveAs NewName

Kill OldPath

Thanks for the tips

Arran

"OssieMac" wrote:

Hi AAran,

Not positive but I think that you might have 2 .xls in your filename.
However, insert a Stop as per the following in the code and then when it
stops.
Select Debug from the dialog box.
Hover the cursor over the variables Oldpath, Newpath and Newname and see
what their value is. You will have your answer as to what you should do.

Dim OldName As String
Dim OldPath As String
Dim NewName As String

OldPath = NewFormWkbk.Path & "\"
OldName = NewFormWkbk.Name

NewName = OldPath & Left(OldName, Len(OldName) - 4) & "- Imported.xls"

Stop
ActiveWorkbook.SaveAs NewName

The following line is definitely incorrect. You do not enclose variables in
double quotes. Only strings entered as strings go in double quotes. There
should not be any double quotes in that line. Also check in Help but I don't
think there are any parenthesis after Kill. eg Kill "fileName.xls" (if using
an actual string name)

Kill ("OldPath & Left(OldName, Len(OldName) - 4)")

Create a string variable for the filename and do like I said above with a
stop and then see what the string value is.

strFileToKill = OldPath & Left(OldName, Len(OldName) - 4)

Stop

Then when the string is correct.

Kill strFileToKill

--
Regards,

OssieMac