How do i save a image to the same folder my .xls file is located?

M

Mr. GetRight

I want to allow the user to tell me where a file(.pdf, .tif,.gif, .doc, etc)
is located. After that I want the progrem to verfy the file exist, then save
a new copy to the same path as my .xls docment and under a new name. Can you
Help?
 
D

Dave Peterson

How about letting the user choose the file. Then you know that it exists.

Option Explicit
Sub testme()
Dim myFileName As Variant
Dim JustFileName As String
Dim NewPath As String

myFileName = Application.GetOpenFilename(filefilter:="All Files, *.*")

If myFileName = False Then
'user hit cancel
Exit Sub
End If

JustFileName = Mid(myFileName, InStrRev(myFileName, "\") + 1)

NewPath = ThisWorkbook.Path 'activeworkbook.path????

FileCopy Source:=myFileName, _
Destination:=NewPath & "\" & JustFileName

End Sub
 
M

Mr. GetRight

Works Perfectly! Thanks a Million!

Dave Peterson said:
How about letting the user choose the file. Then you know that it exists.

Option Explicit
Sub testme()
Dim myFileName As Variant
Dim JustFileName As String
Dim NewPath As String

myFileName = Application.GetOpenFilename(filefilter:="All Files, *.*")

If myFileName = False Then
'user hit cancel
Exit Sub
End If

JustFileName = Mid(myFileName, InStrRev(myFileName, "\") + 1)

NewPath = ThisWorkbook.Path 'activeworkbook.path????

FileCopy Source:=myFileName, _
Destination:=NewPath & "\" & JustFileName

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top