Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 the 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] |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Doris
Maybe the GetOpenFileName method will work for you. http://www.dicks-blog.com/archives/2...topenfilename/ -- 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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 "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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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" wrote in message ... 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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank you guys. It works.
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. Thank you. Doris |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Creating a "Next" button to move the user to the next sheet | Excel Discussion (Misc queries) | |||
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell | Excel Discussion (Misc queries) | |||
Excel "Move or Copy" and "Delete" sheet functions | Excel Worksheet Functions | |||
Why can't I do a "basic search" of my computer in Excel 2007 | New Users to Excel | |||
set up a command button or macro for open file to "save as" | Excel Programming |