Separate Filename and path when saving a file in a macro (excel)

galore

New Member
Joined
Sep 21, 2009
Messages
9
Hi,

Can somebody help in separating Filename and Path when saving a file in a macro (excel).

Sub buclechupi333()
Dim TempFilePath As String
Dim i
MiFile = Application.GetOpenFilename(",*.xls")
If MiFile = False Then Exit Sub
'Here I have a path and filename (all together) and I can not separate it!
Sheets("1").Activate
For i = 1 To 15
TempFilePath = ActiveCell.Value
'So here it is duplicated because I can not dettach the filename from the path.
NewFile = "I:\Basura Temporal\" & TempFilePath & "\" & MiFile & ".xls"
If Dir(NewFile, vbArchive) <> "" Then Kill NewFile
ActiveWorkbook.SaveAs Filename:=NewFile
MsgBox NewFile
ActiveCell.Offset(1, 0).Select
Next i

ActiveWorkbook.Close SaveChanges:=False

End Sub

Thanks,
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Welcome to the Board!

One way is to open the file temporarily, and use some of the Activeworkbook commands on it, i.e.

Code:
    miFile = Application.GetOpenFilename(",*.xls")
    If miFile = False Then Exit Sub
    Workbooks.Open Filename:=miFile
    MyFileName = ActiveWorkbook.Name
    MyFilePath = ActiveWorkbook.Path
    ActiveWorkbook.Close
    ...
 
Upvote 0

Forum statistics

Threads
1,215,518
Messages
6,125,292
Members
449,218
Latest member
Excel Master

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