Anthony's VBA Forum Index Anthony's VBA Forum
Where the knowledge is shared
Menu
 Anthony's VBA Forum IndexHome Page
 Anthony's VBA Forum IndexForum Index
FAQFAQ
MemberlistMemberlist
UsergroupsUsergroups
RegisterRegister
ProfileProfile
Log in to check your private messagesMessages
Log inLogin/Out

Quick Search

Advanced Search

Links
Consulting
Products

Who's Online
[ Administrator ]
[ Moderator ]


Help on how to put GETOPENFILENAME working

 
Post new topic   Reply to topic     Anthony's VBA Forum Index -> General Excel VBA
View previous topic :: View next topic  
Author Message
crackyta



Joined: 29 Dec 2008
Posts: 1

PostPosted: Mon Dec 29, 2008 8:38 am    Post subject: Help on how to put GETOPENFILENAME working Reply with quote

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
View user's profile Send private message
Kenneth Hobson
Gold Member
Gold Member


Joined: 25 Mar 2007
Posts: 21
Location: Tecumseh, OK

PostPosted: Wed Dec 31, 2008 5:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Anthony's VBA Forum Index -> General Excel VBA All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
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