rename file including cell value

neveu

Board Regular
Joined
Jan 27, 2009
Messages
225
hello,
i would like to rename a file using the information from a cell: I1 from worksheet "Buchung"
the final file should be [info from I1] & ["output_1"]&[.mac]
could you please help me to edit it?
thank you

here is my existing code:
Code:
Sub text_saveas_mac_extensions()
'
' Saves the codingdata spreadsheet as text file
'
'
    Sheets("codingdata").Select
    Sheets("codingdata").Copy ' copies to coding spreadsheet
    filelocation = "C:\Documents and Settings\730001108\Desktop\Stapples\AR GE Hamburg - Alexandru Balanescu\" 'sets the location where the file should be saved
    ActiveWorkbook.SaveAs Filename:=filelocation & Format(Date, "dd-mm-yy") & " output_1" & ".txt", FileFormat:=xlTextMSDOS, CreateBackup:=False ' saves file as text file
On Error GoTo Err1
ActiveWorkbook.Close False 'closes the file
oldfilename = filelocation & Format(Date, "dd-mm-yy") & " output_1" & ".txt"
newfilename = filelocation & Format(Date, "dd-mm-yy") & " output_1" & ".mac"
Name oldfilename As newfilename 'changes the file extension from txt to mac
MsgBox ("File Saved As " & " output_1" & ".mac") ' message box confirming the saving of the file and the name under which it has been saved
Err1:  MsgBox ("you've already generated the file for today")
retval = Shell("explorer.EXE " & filelocation, vbNormalFocus) ' open the explorer folder where the file has been saved
Sheets("Buchung").Select
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
For instance:

Code:
Sub text_saveas_mac_extensions()
'
' Saves the codingdata spreadsheet as text file
'

    Sheets("codingdata").Copy    ' copies to coding spreadsheet
    filelocation = "C:\Documents and Settings\730001108\Desktop\Stapples\AR GE Hamburg - Alexandru Balanescu\"    'sets the location where the file should be saved
    ActiveWorkbook.SaveAs Filename:=filelocation & "temp.txt", FileFormat:=xlTextMSDOS, CreateBackup:=False    ' saves file as text file
    On Error GoTo Err1
    ActiveWorkbook.Close False    'closes the file
    oldfilename = filelocation & "temp.txt"
    newfilename = filelocation & Range("I1").Text & " - " & Format(Date, "dd-mm-yy") & " output_1" & ".mac"
    Name oldfilename As newfilename    'changes the file extension from txt to mac
    MsgBox "File Saved As " & " output_1" & ".mac"    ' message box confirming the saving of the file and the name under which it has been saved
Err1:     MsgBox "you've already generated the file for today"
    retval = Shell("explorer.EXE " & filelocation, vbNormalFocus)    ' open the explorer folder where the file has been saved
    Sheets("Buchung").Select
End Sub

Wigi
 
Upvote 0

Forum statistics

Threads
1,224,513
Messages
6,179,214
Members
452,895
Latest member
BILLING GUY

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top