#1   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 234
Default Open Dialog

Excel 2000

I have recorded a macro to open a txt file and then carry out some
formatting, my need is however to run this on several files each with a
different name. How can I display the open file dialog window, select the
file and then run my macro? If I cancel the open dialog window I won't want
to run the macro.

Hopefully this makes sense!

Thanks, Rob


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Open Dialog

use application.GetOpenFileName

this returns the fully qualified path/name of the selected file. You can
then use Open or OpenText to open the file. If the user cancels, it returns
false

Dim wkbk as Workbook
dim fName as Variant
fName = Application.GetOpenFilename( args)
if typename(fName) = "Boolean" then
msgbox "You hit cancel"
exit sub
End If
set wkbk = workbooks.Open( fname)



--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
Excel 2000

I have recorded a macro to open a txt file and then carry out some
formatting, my need is however to run this on several files each with a
different name. How can I display the open file dialog window, select the
file and then run my macro? If I cancel the open dialog window I won't

want
to run the macro.

Hopefully this makes sense!

Thanks, Rob




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 194
Default Open Dialog

Hi, Rob. Check out the VBA Help for Dialogs Collection Object, Dialog
Object, and Show Method and Show Method Example. One important fact is that
the Show Method returns True if a file is opened and False if the user hits
Cancel.

HTH
Ed

"Rob" wrote in message
...
Excel 2000

I have recorded a macro to open a txt file and then carry out some
formatting, my need is however to run this on several files each with a
different name. How can I display the open file dialog window, select the
file and then run my macro? If I cancel the open dialog window I won't

want
to run the macro.

Hopefully this makes sense!

Thanks, Rob




  #4   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 234
Default Open Dialog

Tom,

Thanks for your code, this opens the file but I need to set criteria as to
how the file is opened i.e. what the delimiter is. I guess I need to select
the file, not open but capture the file name and pass it somehow into the
following.

Any pointers will be most welcome. Rob

Workbooks.OpenText Filename:= _
"D:\200040227.msd", _
Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited,
TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=True, Space:=False, Other:=True, OtherChar:="^", FieldInfo:=
_
Array(Array(1, 9), Array(2, 9), Array(3, 1), Array(4, 4), Array(5,
1), Array(6, 1), Array(7 _
, 9), Array(8, 1))

"Tom Ogilvy" wrote in message
...
use application.GetOpenFileName

this returns the fully qualified path/name of the selected file. You can
then use Open or OpenText to open the file. If the user cancels, it

returns
false

Dim wkbk as Workbook
dim fName as Variant
fName = Application.GetOpenFilename( args)
if typename(fName) = "Boolean" then
msgbox "You hit cancel"
exit sub
End If
set wkbk = workbooks.Open( fname)



--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
Excel 2000

I have recorded a macro to open a txt file and then carry out some
formatting, my need is however to run this on several files each with a
different name. How can I display the open file dialog window, select

the
file and then run my macro? If I cancel the open dialog window I won't

want
to run the macro.

Hopefully this makes sense!

Thanks, Rob






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Open Dialog

I said you could use OpenText

Dim wkbk as Workbook
dim fName as Variant
fName = Application.GetOpenFilename( args)
if typename(fName) = "Boolean" then
msgbox "You hit cancel"
exit sub
End If
set wkbk = workbooks.OpenText _
Filename:=fname, _
Origin:=xlWindows, StartRow:=1, _
DataType:=xlDelimited,TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, _
Tab:=True, Semicolon:=False, _
Comma:=True, Space:=False, Other:=True, _
OtherChar:="^", FieldInfo:=Array(Array(1, 9), Array(2, 9), _
Array(3, 1), Array(4, 4), Array(5,1), Array(6, 1), Array(7 _
, 9), Array(8, 1))

--
Regards,
Tom Ogilvy



"Rob" wrote in message
...
Tom,

Thanks for your code, this opens the file but I need to set criteria as to
how the file is opened i.e. what the delimiter is. I guess I need to

select
the file, not open but capture the file name and pass it somehow into the
following.

Any pointers will be most welcome. Rob

Workbooks.OpenText Filename:= _
"D:\200040227.msd", _
Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited,
TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=True, Space:=False, Other:=True, OtherChar:="^",

FieldInfo:=
_
Array(Array(1, 9), Array(2, 9), Array(3, 1), Array(4, 4), Array(5,
1), Array(6, 1), Array(7 _
, 9), Array(8, 1))

"Tom Ogilvy" wrote in message
...
use application.GetOpenFileName

this returns the fully qualified path/name of the selected file. You

can
then use Open or OpenText to open the file. If the user cancels, it

returns
false

Dim wkbk as Workbook
dim fName as Variant
fName = Application.GetOpenFilename( args)
if typename(fName) = "Boolean" then
msgbox "You hit cancel"
exit sub
End If
set wkbk = workbooks.Open( fname)



--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
Excel 2000

I have recorded a macro to open a txt file and then carry out some
formatting, my need is however to run this on several files each with

a
different name. How can I display the open file dialog window, select

the
file and then run my macro? If I cancel the open dialog window I

won't
want
to run the macro.

Hopefully this makes sense!

Thanks, Rob










  #6   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 234
Default Open Dialog

Thanks Tom and Ed, used the code once I understood there was Open and
OpenText.

Thanks again. Rob
"Ed" wrote in message
...
Hi, Rob. Check out the VBA Help for Dialogs Collection Object, Dialog
Object, and Show Method and Show Method Example. One important fact is

that
the Show Method returns True if a file is opened and False if the user

hits
Cancel.

HTH
Ed

"Rob" wrote in message
...
Excel 2000

I have recorded a macro to open a txt file and then carry out some
formatting, my need is however to run this on several files each with a
different name. How can I display the open file dialog window, select

the
file and then run my macro? If I cancel the open dialog window I won't

want
to run the macro.

Hopefully this makes sense!

Thanks, Rob






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 XML dialog box Keithmeister Excel Discussion (Misc queries) 0 March 13th 09 12:20 AM
Open Dialog Box Steven Excel Discussion (Misc queries) 1 January 6th 09 10:10 PM
Open Dialog Box MichaelR Excel Worksheet Functions 1 June 5th 08 05:36 AM
open dialog box Carrie Excel Discussion (Misc queries) 1 January 19th 07 10:43 PM
File open dialog Vaughan Excel Discussion (Misc queries) 0 May 12th 05 08:50 AM


All times are GMT +1. The time now is 10:58 PM.

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"