Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Limiting files to open to only files with certain name.

I have a User Form with a Control Button that is for opening Exsisting Files.
I only want to Open Files with the word "Spec" in the name? Is there a way to
only show & Open Excel Files with "Spec' in the name?

I have the following code that opens the Dialog Box, but it shows all the
files with the ".xlsm" extension. I want to narrow it down to only files with
"Spec" in the name. It would be nice if it would show all the differnt excel
file extensions.


' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

FileToOpen = Application.GetOpenFilename("SPEC" (*.xlsm), *.xlsm")

If FileToOpen = False Then

MsgBox "The Open Method Failed, No Eng Spec was Opened", , "C.E.S."

Exit Sub

End If

Set bk = Workbooks.Open(Filename:=FileToOpen)
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Limiting files to open to only files with certain name.

You didn't say where you wanted the "Spec" to be in the name, so I assumed
in the front...

FileToOpen = Application.GetOpenFilename("SPEC (*.xlsm), Spec*.xlsm")

Note that you had a misplaced quote mark in your example statement.

--
Rick (MVP - Excel)


"Brian" wrote in message
...
I have a User Form with a Control Button that is for opening Exsisting
Files.
I only want to Open Files with the word "Spec" in the name? Is there a way
to
only show & Open Excel Files with "Spec' in the name?

I have the following code that opens the Dialog Box, but it shows all the
files with the ".xlsm" extension. I want to narrow it down to only files
with
"Spec" in the name. It would be nice if it would show all the differnt
excel
file extensions.


' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

FileToOpen = Application.GetOpenFilename("SPEC" (*.xlsm), *.xlsm")

If FileToOpen = False Then

MsgBox "The Open Method Failed, No Eng Spec was Opened", ,
"C.E.S."

Exit Sub

End If

Set bk = Workbooks.Open(Filename:=FileToOpen)
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default Limiting files to open to only files with certain name.

Try this in general module

'---------------------------------------------------
Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

'---------------------------------------------------
Private Function SelectAFile( _
Path As String, _
Optional filtre As String = "*.*") As String
Dim OpenFile As OPENFILENAME, lReturn As Long, sFilter As String
OpenFile.lStructSize = Len(OpenFile)
sFilter = "All Excel Files (" & filtre & ")" & Chr(0) & filtre & Chr(0)
With OpenFile
.lpstrFilter = sFilter
.nFilterIndex = 1
.lpstrFile = String(257, 0)
.nMaxFile = Len(OpenFile.lpstrFile) - 1
.lpstrFileTitle = OpenFile.lpstrFile
.nMaxFileTitle = OpenFile.nMaxFile
.lpstrInitialDir = Path
.lpstrTitle = "Files to Open"
.flags = 0
End With
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
Else
SelectAFile = Trim(Left(OpenFile.lpstrFile, _
InStr(1, OpenFile.lpstrFile, Chr(0)) - 1))
End If
End Function

'---------------------------------------------------
Sub test()
Dim File_to_Open As Variant
Dim Path As String

Path = "c:\"

File_to_Open = SelectAFile(Path, "*Spec*.xlsm")
If File_to_Open < "" Then
MsgBox File_to_Open
End If
End Sub
'---------------------------------------------------

You may combine this string "*Spec*.xlsm" of a number of ways
"Spec*.xlsm : Begin by Spec
"*Spec*.xls* : All excel file having different extensions xls, xlsm...
..../ etc


"Brian" a écrit dans le message de groupe de discussion
: ...
I have a User Form with a Control Button that is for opening Exsisting Files.
I only want to Open Files with the word "Spec" in the name? Is there a way to
only show & Open Excel Files with "Spec' in the name?

I have the following code that opens the Dialog Box, but it shows all the
files with the ".xlsm" extension. I want to narrow it down to only files with
"Spec" in the name. It would be nice if it would show all the differnt excel
file extensions.


' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

FileToOpen = Application.GetOpenFilename("SPEC" (*.xlsm), *.xlsm")

If FileToOpen = False Then

MsgBox "The Open Method Failed, No Eng Spec was Opened", , "C.E.S."

Exit Sub

End If

Set bk = Workbooks.Open(Filename:=FileToOpen)
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Limiting files to open to only files with certain name.

Yes the name is as follows:

"SPEC " & TEO_No_1.Value _
& Space(1) & CLLI_Code_1.Value _
& Space(1) & CES_No_1.Value _
& Space(1) & TEO_Appx_No_2.Value



"Rick Rothstein" wrote:

You didn't say where you wanted the "Spec" to be in the name, so I assumed
in the front...

FileToOpen = Application.GetOpenFilename("SPEC (*.xlsm), Spec*.xlsm")

Note that you had a misplaced quote mark in your example statement.

--
Rick (MVP - Excel)


"Brian" wrote in message
...
I have a User Form with a Control Button that is for opening Exsisting
Files.
I only want to Open Files with the word "Spec" in the name? Is there a way
to
only show & Open Excel Files with "Spec' in the name?

I have the following code that opens the Dialog Box, but it shows all the
files with the ".xlsm" extension. I want to narrow it down to only files
with
"Spec" in the name. It would be nice if it would show all the differnt
excel
file extensions.


' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

FileToOpen = Application.GetOpenFilename("SPEC" (*.xlsm), *.xlsm")

If FileToOpen = False Then

MsgBox "The Open Method Failed, No Eng Spec was Opened", ,
"C.E.S."

Exit Sub

End If

Set bk = Workbooks.Open(Filename:=FileToOpen)
End Sub


.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Limiting files to open to only files with certain name.

It works to open the file, but you can open any of the files no matter what
the name is.

"Rick Rothstein" wrote:

You didn't say where you wanted the "Spec" to be in the name, so I assumed
in the front...

FileToOpen = Application.GetOpenFilename("SPEC (*.xlsm), Spec*.xlsm")

Note that you had a misplaced quote mark in your example statement.

--
Rick (MVP - Excel)


"Brian" wrote in message
...
I have a User Form with a Control Button that is for opening Exsisting
Files.
I only want to Open Files with the word "Spec" in the name? Is there a way
to
only show & Open Excel Files with "Spec' in the name?

I have the following code that opens the Dialog Box, but it shows all the
files with the ".xlsm" extension. I want to narrow it down to only files
with
"Spec" in the name. It would be nice if it would show all the differnt
excel
file extensions.


' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

FileToOpen = Application.GetOpenFilename("SPEC" (*.xlsm), *.xlsm")

If FileToOpen = False Then

MsgBox "The Open Method Failed, No Eng Spec was Opened", ,
"C.E.S."

Exit Sub

End If

Set bk = Workbooks.Open(Filename:=FileToOpen)
End Sub


.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Limiting files to open to only files with certain name.

Check the name of the file after the user gives it to you--and only open it if
you think it's ok:

Option Explicit
' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

Dim FileToOpen As Variant 'could be boolean
Dim bk As Workbook
Dim LastBackSlashPos As Long

FileToOpen = Application.GetOpenFilename("SPEC (*.xlsm), Spec*.xlsm")

If FileToOpen = False Then
MsgBox "The Open Method Failed, No Eng Spec was Opened", , "C.E.S."
Exit Sub
End If

LastBackSlashPos = InStrRev(FileToOpen, "\", -1, vbTextCompare)

If UCase(Mid(FileToOpen, LastBackSlashPos + 1, 4)) < UCase("SPEC") Then
MsgBox "must start with SPEC"
Exit Sub
End If

Set bk = Workbooks.Open(Filename:=FileToOpen)

End Sub

You may want to add a check for the extension or anything else you can think
of...

(instrrev was added in xl2k. If you're supporting xl97, then you'll have to
parse that name some other way (looping backwards from the last character until
you come to a backslash is as good as any).)

Brian wrote:

It works to open the file, but you can open any of the files no matter what
the name is.

"Rick Rothstein" wrote:

You didn't say where you wanted the "Spec" to be in the name, so I assumed
in the front...

FileToOpen = Application.GetOpenFilename("SPEC (*.xlsm), Spec*.xlsm")

Note that you had a misplaced quote mark in your example statement.

--
Rick (MVP - Excel)


"Brian" wrote in message
...
I have a User Form with a Control Button that is for opening Exsisting
Files.
I only want to Open Files with the word "Spec" in the name? Is there a way
to
only show & Open Excel Files with "Spec' in the name?

I have the following code that opens the Dialog Box, but it shows all the
files with the ".xlsm" extension. I want to narrow it down to only files
with
"Spec" in the name. It would be nice if it would show all the differnt
excel
file extensions.


' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

FileToOpen = Application.GetOpenFilename("SPEC" (*.xlsm), *.xlsm")

If FileToOpen = False Then

MsgBox "The Open Method Failed, No Eng Spec was Opened", ,
"C.E.S."

Exit Sub

End If

Set bk = Workbooks.Open(Filename:=FileToOpen)
End Sub


.


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Limiting files to open to only files with certain name.

How would I add the message to read like this

MsgBox = msg Engineer_2.value "you can only a Open Installer Form", ,
"C.E.S."

Engineer_2.value is a value from a combo box.

I tried it but I get a compile Error: Expected End of Statement

What did i do wrong?

"Dave Peterson" wrote:

Check the name of the file after the user gives it to you--and only open it if
you think it's ok:

Option Explicit
' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

Dim FileToOpen As Variant 'could be boolean
Dim bk As Workbook
Dim LastBackSlashPos As Long

FileToOpen = Application.GetOpenFilename("SPEC (*.xlsm), Spec*.xlsm")

If FileToOpen = False Then
MsgBox "The Open Method Failed, No Eng Spec was Opened", , "C.E.S."
Exit Sub
End If

LastBackSlashPos = InStrRev(FileToOpen, "\", -1, vbTextCompare)

If UCase(Mid(FileToOpen, LastBackSlashPos + 1, 4)) < UCase("SPEC") Then
MsgBox "must start with SPEC"
Exit Sub
End If

Set bk = Workbooks.Open(Filename:=FileToOpen)

End Sub

You may want to add a check for the extension or anything else you can think
of...

(instrrev was added in xl2k. If you're supporting xl97, then you'll have to
parse that name some other way (looping backwards from the last character until
you come to a backslash is as good as any).)

Brian wrote:

It works to open the file, but you can open any of the files no matter what
the name is.

"Rick Rothstein" wrote:

You didn't say where you wanted the "Spec" to be in the name, so I assumed
in the front...

FileToOpen = Application.GetOpenFilename("SPEC (*.xlsm), Spec*.xlsm")

Note that you had a misplaced quote mark in your example statement.

--
Rick (MVP - Excel)


"Brian" wrote in message
...
I have a User Form with a Control Button that is for opening Exsisting
Files.
I only want to Open Files with the word "Spec" in the name? Is there a way
to
only show & Open Excel Files with "Spec' in the name?

I have the following code that opens the Dialog Box, but it shows all the
files with the ".xlsm" extension. I want to narrow it down to only files
with
"Spec" in the name. It would be nice if it would show all the differnt
excel
file extensions.


' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

FileToOpen = Application.GetOpenFilename("SPEC" (*.xlsm), *.xlsm")

If FileToOpen = False Then

MsgBox "The Open Method Failed, No Eng Spec was Opened", ,
"C.E.S."

Exit Sub

End If

Set bk = Workbooks.Open(Filename:=FileToOpen)
End Sub

.


--

Dave Peterson
.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Limiting files to open to only files with certain name.

Dim myMsg as string

mymsg = Engineer_2.value & vblf & "You can only open ..."

....

msgbox mymsg

Brian wrote:

How would I add the message to read like this

MsgBox = msg Engineer_2.value "you can only a Open Installer Form", ,
"C.E.S."

Engineer_2.value is a value from a combo box.

I tried it but I get a compile Error: Expected End of Statement

What did i do wrong?

"Dave Peterson" wrote:

Check the name of the file after the user gives it to you--and only open it if
you think it's ok:

Option Explicit
' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

Dim FileToOpen As Variant 'could be boolean
Dim bk As Workbook
Dim LastBackSlashPos As Long

FileToOpen = Application.GetOpenFilename("SPEC (*.xlsm), Spec*.xlsm")

If FileToOpen = False Then
MsgBox "The Open Method Failed, No Eng Spec was Opened", , "C.E.S."
Exit Sub
End If

LastBackSlashPos = InStrRev(FileToOpen, "\", -1, vbTextCompare)

If UCase(Mid(FileToOpen, LastBackSlashPos + 1, 4)) < UCase("SPEC") Then
MsgBox "must start with SPEC"
Exit Sub
End If

Set bk = Workbooks.Open(Filename:=FileToOpen)

End Sub

You may want to add a check for the extension or anything else you can think
of...

(instrrev was added in xl2k. If you're supporting xl97, then you'll have to
parse that name some other way (looping backwards from the last character until
you come to a backslash is as good as any).)

Brian wrote:

It works to open the file, but you can open any of the files no matter what
the name is.

"Rick Rothstein" wrote:

You didn't say where you wanted the "Spec" to be in the name, so I assumed
in the front...

FileToOpen = Application.GetOpenFilename("SPEC (*.xlsm), Spec*.xlsm")

Note that you had a misplaced quote mark in your example statement.

--
Rick (MVP - Excel)


"Brian" wrote in message
...
I have a User Form with a Control Button that is for opening Exsisting
Files.
I only want to Open Files with the word "Spec" in the name? Is there a way
to
only show & Open Excel Files with "Spec' in the name?

I have the following code that opens the Dialog Box, but it shows all the
files with the ".xlsm" extension. I want to narrow it down to only files
with
"Spec" in the name. It would be nice if it would show all the differnt
excel
file extensions.


' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

FileToOpen = Application.GetOpenFilename("SPEC" (*.xlsm), *.xlsm")

If FileToOpen = False Then

MsgBox "The Open Method Failed, No Eng Spec was Opened", ,
"C.E.S."

Exit Sub

End If

Set bk = Workbooks.Open(Filename:=FileToOpen)
End Sub

.


--

Dave Peterson
.


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Limiting files to open to only files with certain name.

ps.

msgbox prompt:=mymsg, title:="C.E.S"
or without the variable:

msgbox prompt:=Engineer_2.value & vblf & "You can only open ...", _
title:="C.E.S"

I like using the named parms (Prompt:=, title:=) instead of using the positional
parameters--who knows how many commas I'd have to use???

Dave Peterson wrote:

Dim myMsg as string

mymsg = Engineer_2.value & vblf & "You can only open ..."

...

msgbox mymsg

Brian wrote:

How would I add the message to read like this

MsgBox = msg Engineer_2.value "you can only a Open Installer Form", ,
"C.E.S."

Engineer_2.value is a value from a combo box.

I tried it but I get a compile Error: Expected End of Statement

What did i do wrong?

"Dave Peterson" wrote:

Check the name of the file after the user gives it to you--and only open it if
you think it's ok:

Option Explicit
' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

Dim FileToOpen As Variant 'could be boolean
Dim bk As Workbook
Dim LastBackSlashPos As Long

FileToOpen = Application.GetOpenFilename("SPEC (*.xlsm), Spec*.xlsm")

If FileToOpen = False Then
MsgBox "The Open Method Failed, No Eng Spec was Opened", , "C.E.S."
Exit Sub
End If

LastBackSlashPos = InStrRev(FileToOpen, "\", -1, vbTextCompare)

If UCase(Mid(FileToOpen, LastBackSlashPos + 1, 4)) < UCase("SPEC") Then
MsgBox "must start with SPEC"
Exit Sub
End If

Set bk = Workbooks.Open(Filename:=FileToOpen)

End Sub

You may want to add a check for the extension or anything else you can think
of...

(instrrev was added in xl2k. If you're supporting xl97, then you'll have to
parse that name some other way (looping backwards from the last character until
you come to a backslash is as good as any).)

Brian wrote:

It works to open the file, but you can open any of the files no matter what
the name is.

"Rick Rothstein" wrote:

You didn't say where you wanted the "Spec" to be in the name, so I assumed
in the front...

FileToOpen = Application.GetOpenFilename("SPEC (*.xlsm), Spec*.xlsm")

Note that you had a misplaced quote mark in your example statement.

--
Rick (MVP - Excel)


"Brian" wrote in message
...
I have a User Form with a Control Button that is for opening Exsisting
Files.
I only want to Open Files with the word "Spec" in the name? Is there a way
to
only show & Open Excel Files with "Spec' in the name?

I have the following code that opens the Dialog Box, but it shows all the
files with the ".xlsm" extension. I want to narrow it down to only files
with
"Spec" in the name. It would be nice if it would show all the differnt
excel
file extensions.


' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

FileToOpen = Application.GetOpenFilename("SPEC" (*.xlsm), *.xlsm")

If FileToOpen = False Then

MsgBox "The Open Method Failed, No Eng Spec was Opened", ,
"C.E.S."

Exit Sub

End If

Set bk = Workbooks.Open(Filename:=FileToOpen)
End Sub

.


--

Dave Peterson
.


--

Dave Peterson


--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Limiting files to open to only files with certain name.

I am getting a Compile Error: syntax error
mymsg = Engineer_2.value & vblf & "You can only open ..."


Dave Peterson" wrote:

Dim myMsg as string

mymsg = Engineer_2.value & vblf & "You can only open ..."

....

msgbox mymsg

Brian wrote:

How would I add the message to read like this

MsgBox = msg Engineer_2.value "you can only a Open Installer Form", ,
"C.E.S."

Engineer_2.value is a value from a combo box.

I tried it but I get a compile Error: Expected End of Statement

What did i do wrong?

"Dave Peterson" wrote:

Check the name of the file after the user gives it to you--and only open it if
you think it's ok:

Option Explicit
' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

Dim FileToOpen As Variant 'could be boolean
Dim bk As Workbook
Dim LastBackSlashPos As Long

FileToOpen = Application.GetOpenFilename("SPEC (*.xlsm), Spec*.xlsm")

If FileToOpen = False Then
MsgBox "The Open Method Failed, No Eng Spec was Opened", , "C.E.S."
Exit Sub
End If

LastBackSlashPos = InStrRev(FileToOpen, "\", -1, vbTextCompare)

If UCase(Mid(FileToOpen, LastBackSlashPos + 1, 4)) < UCase("SPEC") Then
MsgBox "must start with SPEC"
Exit Sub
End If

Set bk = Workbooks.Open(Filename:=FileToOpen)

End Sub

You may want to add a check for the extension or anything else you can think
of...

(instrrev was added in xl2k. If you're supporting xl97, then you'll have to
parse that name some other way (looping backwards from the last character until
you come to a backslash is as good as any).)

Brian wrote:

It works to open the file, but you can open any of the files no matter what
the name is.

"Rick Rothstein" wrote:

You didn't say where you wanted the "Spec" to be in the name, so I assumed
in the front...

FileToOpen = Application.GetOpenFilename("SPEC (*.xlsm), Spec*.xlsm")

Note that you had a misplaced quote mark in your example statement.

--
Rick (MVP - Excel)


"Brian" wrote in message
...
I have a User Form with a Control Button that is for opening Exsisting
Files.
I only want to Open Files with the word "Spec" in the name? Is there a way
to
only show & Open Excel Files with "Spec' in the name?

I have the following code that opens the Dialog Box, but it shows all the
files with the ".xlsm" extension. I want to narrow it down to only files
with
"Spec" in the name. It would be nice if it would show all the differnt
excel
file extensions.


' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

FileToOpen = Application.GetOpenFilename("SPEC" (*.xlsm), *.xlsm")

If FileToOpen = False Then

MsgBox "The Open Method Failed, No Eng Spec was Opened", ,
"C.E.S."

Exit Sub

End If

Set bk = Workbooks.Open(Filename:=FileToOpen)
End Sub

.


--

Dave Peterson
.


--

Dave Peterson
.



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Limiting files to open to only files with certain name.

I'd guess you made a typing error that you didn't share.

Brian wrote:

I am getting a Compile Error: syntax error
mymsg = Engineer_2.value & vblf & "You can only open ..."

Dave Peterson" wrote:

Dim myMsg as string

mymsg = Engineer_2.value & vblf & "You can only open ..."

....

msgbox mymsg

Brian wrote:

How would I add the message to read like this

MsgBox = msg Engineer_2.value "you can only a Open Installer Form", ,
"C.E.S."

Engineer_2.value is a value from a combo box.

I tried it but I get a compile Error: Expected End of Statement

What did i do wrong?

"Dave Peterson" wrote:

Check the name of the file after the user gives it to you--and only open it if
you think it's ok:

Option Explicit
' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

Dim FileToOpen As Variant 'could be boolean
Dim bk As Workbook
Dim LastBackSlashPos As Long

FileToOpen = Application.GetOpenFilename("SPEC (*.xlsm), Spec*.xlsm")

If FileToOpen = False Then
MsgBox "The Open Method Failed, No Eng Spec was Opened", , "C.E.S."
Exit Sub
End If

LastBackSlashPos = InStrRev(FileToOpen, "\", -1, vbTextCompare)

If UCase(Mid(FileToOpen, LastBackSlashPos + 1, 4)) < UCase("SPEC") Then
MsgBox "must start with SPEC"
Exit Sub
End If

Set bk = Workbooks.Open(Filename:=FileToOpen)

End Sub

You may want to add a check for the extension or anything else you can think
of...

(instrrev was added in xl2k. If you're supporting xl97, then you'll have to
parse that name some other way (looping backwards from the last character until
you come to a backslash is as good as any).)

Brian wrote:

It works to open the file, but you can open any of the files no matter what
the name is.

"Rick Rothstein" wrote:

You didn't say where you wanted the "Spec" to be in the name, so I assumed
in the front...

FileToOpen = Application.GetOpenFilename("SPEC (*.xlsm), Spec*.xlsm")

Note that you had a misplaced quote mark in your example statement.

--
Rick (MVP - Excel)


"Brian" wrote in message
...
I have a User Form with a Control Button that is for opening Exsisting
Files.
I only want to Open Files with the word "Spec" in the name? Is there a way
to
only show & Open Excel Files with "Spec' in the name?

I have the following code that opens the Dialog Box, but it shows all the
files with the ".xlsm" extension. I want to narrow it down to only files
with
"Spec" in the name. It would be nice if it would show all the differnt
excel
file extensions.


' Open Existing Eng Spec 9 Control Button
Private Sub Open_Existing_Eng_Spec_9_Click()

FileToOpen = Application.GetOpenFilename("SPEC" (*.xlsm), *.xlsm")

If FileToOpen = False Then

MsgBox "The Open Method Failed, No Eng Spec was Opened", ,
"C.E.S."

Exit Sub

End If

Set bk = Workbooks.Open(Filename:=FileToOpen)
End Sub

.


--

Dave Peterson
.


--

Dave Peterson
.


--

Dave Peterson
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 Text Files/Format/Save as .xls for multiple files. Ray Excel Programming 9 June 9th 09 04:23 PM
How to change default Open/Files of Type to "Microsoft Excel Files Tammy Excel Discussion (Misc queries) 2 January 14th 08 11:06 PM
Limiting files to a single computer Berj Excel Discussion (Misc queries) 1 September 15th 06 09:12 PM
Macro to open *.dat files and save as .txt (comma delimited text files) [email protected] Excel Programming 2 November 30th 05 05:50 AM


All times are GMT +1. The time now is 12:45 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"