Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8
Default Browse For a File or Path and enter in a cell

Is it posssible in Excel 2003 to Browse to either select a file name or path
that would be entered in a cell for reference or used in a macro?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Browse For a File or Path and enter in a cell

You could use:

Dim myFileName as variant
myfilename = application.getopenfilename
if myfilename = false then
'use hit cancel
else
activesheet.range("a1").value = myfilename
end if

But I'm not sure what you're really asking.

D. Jones wrote:

Is it posssible in Excel 2003 to Browse to either select a file name or path
that would be entered in a cell for reference or used in a macro?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 284
Default Browse For a File or Path and enter in a cell

Here is an option that will give you a browse window for files with the
initial focus on the 'My Documents' folder. You probably want to do
something more interesting than have a message box pop up with the path and
file name for each selected item though.

__________________________________

Sub UserGetMyDocsFiles()

Dim fd As FileDialog
Dim vrtSelectedItem As Variant

' Determine Path to the My Documents folder
Set objShell = CreateObject("Shell.Application")
Set objMyDocsFldr = objShell.Namespace(&H5&)
strMyDocsPath = objMyDocsFldr.Self.Path

' Create a file picker dialog opening to My Documents
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
..Filters.Clear
..InitialFileName = strMyDocsPath
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
MsgBox vrtSelectedItem
Next vrtSelectedItem
End If
End With

Set objShell = Nothing
Set fd = Nothing

End Sub

___________________________________

Steve Yandl



"D. Jones" wrote in message
...
Is it posssible in Excel 2003 to Browse to either select a file name or
path
that would be entered in a cell for reference or used in a macro?



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8
Default Browse For a File or Path and enter in a cell

I will try to make my question clearer.

I would like to enter a file name in a cell and the path to that file name
in another to use later is a couple of macros.

I would like to use a browse type window (Like in Excel to find a "Save As"
directory location) to select the file and path to that file and have them
entered into a cell in Excel.

"Dave Peterson" wrote:

You could use:

Dim myFileName as variant
myfilename = application.getopenfilename
if myfilename = false then
'use hit cancel
else
activesheet.range("a1").value = myfilename
end if

But I'm not sure what you're really asking.

D. Jones wrote:

Is it posssible in Excel 2003 to Browse to either select a file name or path
that would be entered in a cell for reference or used in a macro?


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Browse For a File or Path and enter in a cell

Dim myFileName as string
dim teststr as string

with thisworkbook.worksheets("somesheetname")
myfilename = .range("a1").value & "\" & .range("b1").value
end with

teststr = ""
on error resume next
teststr = dir(myfilename)
on error goto 0

if teststr = "" then
msgbox "That file doesn't exist!
else
'do your stuff
end if

I don't understand the second portion of your question. If you put the name of
the file in a cell and the path in a different cell, then don't you already know
the location of the file and folder?

D. Jones wrote:

I will try to make my question clearer.

I would like to enter a file name in a cell and the path to that file name
in another to use later is a couple of macros.

I would like to use a browse type window (Like in Excel to find a "Save As"
directory location) to select the file and path to that file and have them
entered into a cell in Excel.

"Dave Peterson" wrote:

You could use:

Dim myFileName as variant
myfilename = application.getopenfilename
if myfilename = false then
'use hit cancel
else
activesheet.range("a1").value = myfilename
end if

But I'm not sure what you're really asking.

D. Jones wrote:

Is it posssible in Excel 2003 to Browse to either select a file name or path
that would be entered in a cell for reference or used in a macro?


--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 284
Default Browse For a File or Path and enter in a cell

Here is a modified version of the sub I posted earlier. This time, when the
user selects files and clicks 'OK', each file name is appended to Column A
and the corresponding path to the selected file is placed in Column B.

______________________________________

Sub UserGetMyDocsFiles()

Dim fd As FileDialog
Dim vrtSelectedItem As Variant
Dim R As Integer
Dim strPathName As String
Dim strFileName As String

R = Range("A65536").End(xlUp).Row + 1

' Determine Path to the My Documents folder
Set objShell = CreateObject("Shell.Application")
Set objMyDocsFldr = objShell.Namespace(&H5&)
strMyDocsPath = objMyDocsFldr.Self.Path

' Create a file picker dialog opening to My Documents
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
..Filters.Clear
..InitialFileName = strMyDocsPath
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
arrFullName = Split(vrtSelectedItem, "\")
strPathName = ""
strFileName = ""
strFileName = arrFullName(UBound(arrFullName))
For X = 0 To UBound(arrFullName) - 1
strPathName = strPathName & arrFullName(X) & "\"
Next X
Cells(R, 1).Value = strFileName
Cells(R, 2).Value = strPathName
R = R + 1
Next vrtSelectedItem
End If
End With

Set objShell = Nothing
Set fd = Nothing

End Sub
_____________________________________

Steve Yandl



"D. Jones" wrote in message
...
Is it posssible in Excel 2003 to Browse to either select a file name or
path
that would be entered in a cell for reference or used in a macro?



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
Using UNC path instead of URL to link cell to PDF file Francisco Excel Worksheet Functions 2 May 24th 07 10:30 PM
Formula too long - new file path is shorter than old file path - Excel 2003 Greg J Excel Worksheet Functions 1 November 22nd 06 05:16 PM
Browse File for Mac John Vickers Excel Discussion (Misc queries) 1 February 17th 06 06:23 PM
Browse button on form for folder path Greshter Excel Discussion (Misc queries) 2 January 12th 06 10:20 PM
can't browse file k_anucha Excel Discussion (Misc queries) 1 September 29th 05 01:51 AM


All times are GMT +1. The time now is 03:35 PM.

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"