Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Copy user selected files to new folder.

I know I'm missing a critical piece but can't figure it out. How do I get
just the name of the file they selected (without path)?

Sub CopyFilesMacro()

Application.ScreenUpdating = False

Sheets("Input").Select
MyPath = Range("B2").Value

MsgBox ("As soon as you click the OK button, a Browse Dialog box will " _
& "pop up. Use it to choose the files you want to copy to the
location shown " _
& "in cell B2 of the Input sheet.")

Dim fd As FileDialog

Set fd = Application.FileDialog(msoFileDialogFilePicker)

Dim vrtSelectedItem As Variant

With fd

If .Show = -1 Then

For Each vrtSelectedItem In .SelectedItems

FileCopy vrtSelectedItem, MyPath & "\" &
vrtSelectedItem.Name & ".xls"

Next vrtSelectedItem
Else
End If
End With

Set fd = Nothing
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Copy user selected files to new folder.

Try something like the following:

For Each vrtSelectedItem In .SelectedItems
FileNameOnly = Mid(vrtSelectedItem, _
InStrRev(vrtSelectedItem, "\") + 1)
Debug.Print FileNameOnly
Next vrtSelectedItem



Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)

On Tue, 10 Mar 2009 14:34:04 -0700, Keithlo
wrote:

I know I'm missing a critical piece but can't figure it out. How do I get
just the name of the file they selected (without path)?

Sub CopyFilesMacro()

Application.ScreenUpdating = False

Sheets("Input").Select
MyPath = Range("B2").Value

MsgBox ("As soon as you click the OK button, a Browse Dialog box will " _
& "pop up. Use it to choose the files you want to copy to the
location shown " _
& "in cell B2 of the Input sheet.")

Dim fd As FileDialog

Set fd = Application.FileDialog(msoFileDialogFilePicker)

Dim vrtSelectedItem As Variant

With fd

If .Show = -1 Then

For Each vrtSelectedItem In .SelectedItems

FileCopy vrtSelectedItem, MyPath & "\" &
vrtSelectedItem.Name & ".xls"

Next vrtSelectedItem
Else
End If
End With

Set fd = Nothing
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Copy user selected files to new folder.

Here is one way. Be careful of the file extension. If you have them visible
on your system you do not need it in the destination path. It will be part
of the file name.


For Each vrtSelectedItem In .SelectedItems
Set Fso = CreateObject("Scripting.FileSystemObject")
fName = Fso.GetFileName(vrtSelectedItem)
MsgBox fName
FileCopy vrtSelectedItem, MyPath & "\" & fName & ".xls"
'<<Caution

Next vrtSelectedItem




"Keithlo" wrote:

I know I'm missing a critical piece but can't figure it out. How do I get
just the name of the file they selected (without path)?

Sub CopyFilesMacro()

Application.ScreenUpdating = False

Sheets("Input").Select
MyPath = Range("B2").Value

MsgBox ("As soon as you click the OK button, a Browse Dialog box will " _
& "pop up. Use it to choose the files you want to copy to the
location shown " _
& "in cell B2 of the Input sheet.")

Dim fd As FileDialog

Set fd = Application.FileDialog(msoFileDialogFilePicker)

Dim vrtSelectedItem As Variant

With fd

If .Show = -1 Then

For Each vrtSelectedItem In .SelectedItems

FileCopy vrtSelectedItem, MyPath & "\" &
vrtSelectedItem.Name & ".xls"

Next vrtSelectedItem
Else
End If
End With

Set fd = Nothing
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Copy user selected files to new folder.

Thanks very much, Chip. I will try this.

"Chip Pearson" wrote:

Try something like the following:

For Each vrtSelectedItem In .SelectedItems
FileNameOnly = Mid(vrtSelectedItem, _
InStrRev(vrtSelectedItem, "\") + 1)
Debug.Print FileNameOnly
Next vrtSelectedItem



Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)

On Tue, 10 Mar 2009 14:34:04 -0700, Keithlo
wrote:

I know I'm missing a critical piece but can't figure it out. How do I get
just the name of the file they selected (without path)?

Sub CopyFilesMacro()

Application.ScreenUpdating = False

Sheets("Input").Select
MyPath = Range("B2").Value

MsgBox ("As soon as you click the OK button, a Browse Dialog box will " _
& "pop up. Use it to choose the files you want to copy to the
location shown " _
& "in cell B2 of the Input sheet.")

Dim fd As FileDialog

Set fd = Application.FileDialog(msoFileDialogFilePicker)

Dim vrtSelectedItem As Variant

With fd

If .Show = -1 Then

For Each vrtSelectedItem In .SelectedItems

FileCopy vrtSelectedItem, MyPath & "\" &
vrtSelectedItem.Name & ".xls"

Next vrtSelectedItem
Else
End If
End With

Set fd = Nothing
End Sub


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Copy user selected files to new folder.

Thanks very much, JLGWhiz. I will try this.

"JLGWhiz" wrote:

Here is one way. Be careful of the file extension. If you have them visible
on your system you do not need it in the destination path. It will be part
of the file name.


For Each vrtSelectedItem In .SelectedItems
Set Fso = CreateObject("Scripting.FileSystemObject")
fName = Fso.GetFileName(vrtSelectedItem)
MsgBox fName
FileCopy vrtSelectedItem, MyPath & "\" & fName & ".xls"
'<<Caution

Next vrtSelectedItem




"Keithlo" wrote:

I know I'm missing a critical piece but can't figure it out. How do I get
just the name of the file they selected (without path)?

Sub CopyFilesMacro()

Application.ScreenUpdating = False

Sheets("Input").Select
MyPath = Range("B2").Value

MsgBox ("As soon as you click the OK button, a Browse Dialog box will " _
& "pop up. Use it to choose the files you want to copy to the
location shown " _
& "in cell B2 of the Input sheet.")

Dim fd As FileDialog

Set fd = Application.FileDialog(msoFileDialogFilePicker)

Dim vrtSelectedItem As Variant

With fd

If .Show = -1 Then

For Each vrtSelectedItem In .SelectedItems

FileCopy vrtSelectedItem, MyPath & "\" &
vrtSelectedItem.Name & ".xls"

Next vrtSelectedItem
Else
End If
End With

Set fd = Nothing
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Copy user selected files to new folder.

You were right about the file extension. In my case it was part of the file
name. Thanks for that additional info.

"JLGWhiz" wrote:

Here is one way. Be careful of the file extension. If you have them visible
on your system you do not need it in the destination path. It will be part
of the file name.


For Each vrtSelectedItem In .SelectedItems
Set Fso = CreateObject("Scripting.FileSystemObject")
fName = Fso.GetFileName(vrtSelectedItem)
MsgBox fName
FileCopy vrtSelectedItem, MyPath & "\" & fName & ".xls"
'<<Caution

Next vrtSelectedItem




"Keithlo" wrote:

I know I'm missing a critical piece but can't figure it out. How do I get
just the name of the file they selected (without path)?

Sub CopyFilesMacro()

Application.ScreenUpdating = False

Sheets("Input").Select
MyPath = Range("B2").Value

MsgBox ("As soon as you click the OK button, a Browse Dialog box will " _
& "pop up. Use it to choose the files you want to copy to the
location shown " _
& "in cell B2 of the Input sheet.")

Dim fd As FileDialog

Set fd = Application.FileDialog(msoFileDialogFilePicker)

Dim vrtSelectedItem As Variant

With fd

If .Show = -1 Then

For Each vrtSelectedItem In .SelectedItems

FileCopy vrtSelectedItem, MyPath & "\" &
vrtSelectedItem.Name & ".xls"

Next vrtSelectedItem
Else
End If
End With

Set fd = Nothing
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
User selection of folder and open all .xls files within folder Barb Reinhardt Excel Programming 4 April 14th 07 01:41 PM
"Folder Select" Dialogue - Opening multiple files from selected folder Rob[_26_] Excel Programming 2 September 30th 05 02:47 PM
How to copy 30 csv files from a folder to another folder ddiicc Excel Programming 1 July 17th 05 09:42 AM
getting filenames from a user selected folder Mitch Excel Programming 3 June 10th 05 04:55 PM
User name & password access to Excel files in a folder Maria[_6_] Excel Programming 4 November 17th 03 06:44 PM


All times are GMT +1. The time now is 01:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"