Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Open file Dialog box in Macro

Ok, I'll do my best to explain what my problem is. I have
a macro that I run to import a text file, format it, sort
it and manipulate the workbook in a few other ways. My
problem comes in that the file's name is not always the
same so I don't want to hardcode the filename into it. I
want instead to have a "Browse" dialog box pop up and the
user be able to select a file to open for the macro to
use. Any help is greatly appreciated. Let me know if
there's something I can help clear up for you.

Joshua Dunn
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Open file Dialog box in Macro

fname = Application.GetOpenFilename()

workbooks.openText Filename:=fname, . . .

--
Regards,
Tom Ogilvy

"Joshua" wrote in message
...
Ok, I'll do my best to explain what my problem is. I have
a macro that I run to import a text file, format it, sort
it and manipulate the workbook in a few other ways. My
problem comes in that the file's name is not always the
same so I don't want to hardcode the filename into it. I
want instead to have a "Browse" dialog box pop up and the
user be able to select a file to open for the macro to
use. Any help is greatly appreciated. Let me know if
there's something I can help clear up for you.

Joshua Dunn



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Open file Dialog box in Macro

Have a look at:

Application.GetOpenFilename

--
Jim Rech
Excel MVP
"Joshua" wrote in message
...
| Ok, I'll do my best to explain what my problem is. I have
| a macro that I run to import a text file, format it, sort
| it and manipulate the workbook in a few other ways. My
| problem comes in that the file's name is not always the
| same so I don't want to hardcode the filename into it. I
| want instead to have a "Browse" dialog box pop up and the
| user be able to select a file to open for the macro to
| use. Any help is greatly appreciated. Let me know if
| there's something I can help clear up for you.
|
| Joshua Dunn


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Open file Dialog box in Macro

Hi Joshua,

Help has a great example

fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen < False Then
workbooks.Open filename:= fileToOpen
End If
--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Joshua" wrote in message
...
Ok, I'll do my best to explain what my problem is. I have
a macro that I run to import a text file, format it, sort
it and manipulate the workbook in a few other ways. My
problem comes in that the file's name is not always the
same so I don't want to hardcode the filename into it. I
want instead to have a "Browse" dialog box pop up and the
user be able to select a file to open for the macro to
use. Any help is greatly appreciated. Let me know if
there's something I can help clear up for you.

Joshua Dunn



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Open file Dialog box in Macro

Thanks Guys,
That works. Could you tell me how to change the starting
directory in the Open dialog box? I want it to start in a
Network Share directory rather than in the default "My
Documents" folder.

Thanks again,
Joshua Dunn

-----Original Message-----
Hi Joshua,

Help has a great example

fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen < False Then
workbooks.Open filename:= fileToOpen
End If
--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Joshua" wrote in

message
...
Ok, I'll do my best to explain what my problem is. I

have
a macro that I run to import a text file, format it,

sort
it and manipulate the workbook in a few other ways. My
problem comes in that the file's name is not always the
same so I don't want to hardcode the filename into it.

I
want instead to have a "Browse" dialog box pop up and

the
user be able to select a file to open for the macro to
use. Any help is greatly appreciated. Let me know if
there's something I can help clear up for you.

Joshua Dunn



.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Open file Dialog box in Macro

Joshua,

Precede the GetFileOpen with

ChDrive "C:\"
ChDir "C:\MyTest"

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Joshua" wrote in message
...
Thanks Guys,
That works. Could you tell me how to change the starting
directory in the Open dialog box? I want it to start in a
Network Share directory rather than in the default "My
Documents" folder.

Thanks again,
Joshua Dunn

-----Original Message-----
Hi Joshua,

Help has a great example

fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen < False Then
workbooks.Open filename:= fileToOpen
End If
--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Joshua" wrote in

message
...
Ok, I'll do my best to explain what my problem is. I

have
a macro that I run to import a text file, format it,

sort
it and manipulate the workbook in a few other ways. My
problem comes in that the file's name is not always the
same so I don't want to hardcode the filename into it.

I
want instead to have a "Browse" dialog box pop up and

the
user be able to select a file to open for the macro to
use. Any help is greatly appreciated. Let me know if
there's something I can help clear up for you.

Joshua Dunn



.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Open file Dialog box in Macro

And if the network share is not mapped to a drive letter you could use:

Private Declare Function SetCurrentDirectoryA Lib "kernel32" _
(ByVal lpPathName As String) As Long

Public Sub bSetUNCPath(ByVal szPathToSet As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPathToSet)
End Sub


Then you would put in your code

bRes = bSetUNCPath("\\ComputerName\Directory")

Make sure you put the Declare statement at the top of the general module
where you will use the code.

Code originally posted by Rob Bovey.

--
Regards,
Tom Ogilvy


"Joshua" wrote in message
...
Thanks Guys,
That works. Could you tell me how to change the starting
directory in the Open dialog box? I want it to start in a
Network Share directory rather than in the default "My
Documents" folder.

Thanks again,
Joshua Dunn

-----Original Message-----
Hi Joshua,

Help has a great example

fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen < False Then
workbooks.Open filename:= fileToOpen
End If
--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Joshua" wrote in

message
...
Ok, I'll do my best to explain what my problem is. I

have
a macro that I run to import a text file, format it,

sort
it and manipulate the workbook in a few other ways. My
problem comes in that the file's name is not always the
same so I don't want to hardcode the filename into it.

I
want instead to have a "Browse" dialog box pop up and

the
user be able to select a file to open for the macro to
use. Any help is greatly appreciated. Let me know if
there's something I can help clear up for you.

Joshua Dunn



.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open File Dialog box looks like Steven Excel Discussion (Misc queries) 3 January 30th 10 07:44 PM
File open dialog box [email protected] Excel Discussion (Misc queries) 1 March 21st 07 03:01 AM
File open dialog Vaughan Excel Discussion (Misc queries) 0 May 12th 05 08:50 AM
open file dialog-select file-import worksheet Divinedar Excel Programming 1 January 16th 04 07:13 PM
File open dialog Jan Kronsell[_2_] Excel Programming 1 September 5th 03 08:56 AM


All times are GMT +1. The time now is 05:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"