|
Anthony's VBA Forum Where the knowledge is shared |
|
|
View previous topic :: View next topic |
Author |
Message |
crackyta
Joined: 29 Dec 2008 Posts: 1
|
Posted: Mon Dec 29, 2008 8:38 am Post subject: Help on how to put GETOPENFILENAME working |
|
|
hI EVERYONE,
I am new in this fórum.
I need to use the GETOPENFILENAME to specify the pathname to bring my files to use in calcul in a specific cell
I need to open a commondialog every time i select a specific cell (b2)
I now how to program the sub openfile but i don't now how to put the sub working when i select the cell.
Could anyone help me?
Sorry for my english i'm to bad.
Thank you. |
|
Back to top |
|
|
Kenneth Hobson Gold Member
Joined: 25 Mar 2007 Posts: 21 Location: Tecumseh, OK
|
Posted: Wed Dec 31, 2008 5:36 pm Post subject: |
|
|
Welcome to the forum!
Not sure why this forum doesn't use the code tags properly. Remove the [code] and [/code]'s.
Right click your sheet's tab, View Code, and paste:
[code]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address <> "$B$2" Then Exit Sub
Test
End Sub[/code]
In a Module, put your Test Sub something like:
[code]Sub Test()
Dim filespec As Variant, i As Integer
'filespec = "c:\myfiles\test.xls"
On Error GoTo EndNow
filespec = Application.GetOpenFilename(FileFilter:="microsoft excel files (*.xls), *.xls", Title:="Get File", MultiSelect:=True)
'MsgBox GetFileName(filespec)
For i = 1 To UBound(filespec)
MsgBox filespec(i), , GetFileName(CStr(filespec(i)))
Next i
EndNow:
End Sub
' MsgBox GetFileName(filespec(0))
Function GetFileName(filespec As String)
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
GetFileName = fso.GetFileName(filespec)
End Function
[/code]
I use FileDialog for 2003+.[/code] |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2002 phpBB Group
|