Google グループは Usenet の新規の投稿と購読のサポートを終了しました。過去のコンテンツは引き続き閲覧できます。
Dismiss

Re: a button to open up "My Computer" on an excel sheet

閲覧: 5 回
最初の未読メッセージにスキップ

Jake Marx

未読、
2005/08/16 15:17:212005/08/16
To:
Hi Doris,

DorisM wrote:
> I'm trying to create a command button using VBA in an excel sheet
> that opens up "My Computer". So it will allow the user to go to
> whatever folder that they have their file saved at. Similar to the
> "Open" command in most window applications.
>
> I'm at level I in VBA, so I'm not sure if this is possible.

The GetOpenFilename method will allow the user to select a file. Here's
some sample code that shows how to use it:

Sub DemoFileSelect()
Dim vResponse As Variant

vResponse = Application.GetOpenFilename( _
FileFilter:="Microsoft Excel Files (*.xls), *.xls", _
Title:="Please select your file")

If vResponse <> False Then
MsgBox Prompt:="You selected '" & vResponse & "'.", _
Buttons:=vbOKOnly Or vbInformation
Else
MsgBox Prompt:="You cancelled.", _
Buttons:=vbOKOnly Or vbInformation
End If
End Sub

If you drop a CommandButton from the Control Toolbox onto your worksheet,
you can double-click it and call the demo from there:

Private Sub CommandButton1_Click()
DemoFileSelect
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

Dick Kusleika

未読、
2005/08/16 15:18:142005/08/16
To:
Doris

Maybe the GetOpenFileName method will work for you.

http://www.dicks-blog.com/archives/2004/06/09/getopenfilename/


--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

DorisM wrote:
> I'm trying to create a command button using VBA in an excel sheet
> that opens up "My Computer". So it will allow the user to go to
> whatever folder that they have their file saved at. Similar to the
> "Open" command in most window applications.
>
> I'm at level I in VBA, so I'm not sure if this is possible.
>

> Thank you.
>
> Doris


sebastienm

未読、
2005/08/16 15:22:032005/08/16
To:
Hi,

The GetOpenFileName function display the regular Open dialog and the user
can browse and choose a file. Once the user clicks Ok or Cancel, the
GetOpenFileName function returns a string containing the path+name of the
selected file (or False if the user clicked Cancel). Impoirtant: The function
doesn't open the file, it just retuns its path+name, so you need some
additional code to process the file (open it, print it, or whatever you need
to do). (see online help for more info)

1- in a module, add the code to let a user choose a file:
Sub UserChooseFile()
Dim f As Variant
f = Application.GetOpenFilename("Excel File (*.xl),*.xls", , "Open
dialog test")
If f <> False Then
MsgBox "Open " & f
Else
MsgBox "the Open was cancelled"
End If
'***** add process code here ******
End Sub
2-on a sheet, add a button from the Forms toolbar (not the Control Toolbox
toolbar; menu View > Toolbars > Forms)
If the Macro dialog doesn't popup right away, just right click the button
and choose Assign Macro. There choose the UserChooseFile macro.

I hope this helps,
--
Regards,
Sébastien
<http://www.ondemandanalysis.com>

Tom Ogilvy

未読、
2005/08/16 15:24:082005/08/16
To:
fname = Application.GetOpenFileName()

shows the file open dialog and allows traversing directories to find or
establish the location of the file.

for saving

fName = Application.GetSaveAsFileName()

Note that neither of these open or save the file selected - they return the
fully qualified name as a string

--
Regards,
Tom Ogilvy


"DorisM" <Dor...@discussions.microsoft.com> wrote in message
news:A5C231D7-2F25-47A5...@microsoft.com...

DorisM

未読、
2005/08/16 15:32:062005/08/16
To:
Thank you guys. It works.

Doris

新着メール 0 件