View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default file browser when a cell in selected

And what would happen if the user chose a name the first time, but clicked
cancel the second?



Lorne wrote:

Dear Hank,

I am teaching myself VBA by reading this newsgroup and getting understanding
the code you all kindly put on it and can now do quite a surprising amount
of things, but I have a question. Almost always the code sets something
equal to a variable and then tests the variable rather than simply testing
whatever the something is - you do it in your solution below & so does Frank
Kabel in the same thread. Why don't you use:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Address < $A$2" Then Exit Sub
If Application.GetOpenFilename("Excel Files (*.xls), *.xls") Then
Target.Value = Application.GetOpenFilename("Excel Files (*.xls),
*.xls")
End If

End Sub

I am trying to understand if there is a technical reason for the extra steps
of creating the variable vnt and setting it equal to
Application.GetOpenFilename or whether it is just the way everyone is taught
to do it.

Many thanks if you can spare the time help (or if there is a web resource to
answer such questions).

"Hank Scorpio" wrote in message
...
On Tue, 3 Feb 2004 04:46:35 -0600, dreamer
wrote:

Is there a way to make the dialog box which opens a file appear when a
certain cell is selected? For example if cell A2 is selected, a
dialogbox for opening a file asks user which file should be opened and
the writes the name of the file to cell A2.


Right click on the sheet tab and select "View Code", then paste this
into the module that appears:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim vnt As Variant

If Target.Address = "$A$2" Then

vnt = Application.GetOpenFilename("Excel Files (*.xls), *.xls")

If vnt = False Then
Exit Sub
Else
Target.Value = vnt
End If

End If

End Sub

---------------------------------------------------------
Hank Scorpio
scorpionet who hates spam is at iprimus.com.au (You know what to do.)
* Please keep all replies in this Newsgroup. Thanks! *


--

Dave Peterson