Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Open existing file

I am trying to open existing files in Excel. I am using the GetOpenFilename
method to select the files.

Sub SelectBookToOpen()

Dim FileToOpen As Variant
Dim MyPath As String
Dim Wb As Workbook

MyPath = "T:\Archive"
ChDrive "T"
ChDir MyPath

FileToOpen = Application.GetOpenFilename("Excel Files (*.xls), *.xls", , _
"Please select both previous and current weeks' Data Archives", , True)

If FileToOpen < False Then
Set Wb = Workbooks.Open(FileToOpen)
Else
Exit Sub
End If

End Sub

Everything works fine until I actually select a file and click Open. Then I
get a data mismatch error on this line: If FileToOpen < False Then

What am I doing wrong?
Thanks, Lee
  #2   Report Post  
Posted to microsoft.public.excel.programming
PO PO is offline
external usenet poster
 
Posts: 66
Default Open existing file

Hi FinChase

If the user doesn't select a file, GetOpenFilename returns False (Boolean
value). If the user however selects one or more files GetOpenFilename
returns an array of variants.

Try this:

Sub SelectBookToOpen()

Dim FileToOpen As Variant
Dim MyPath As String
Dim Wb As Workbook
Dim i As Integer

MyPath = "T:\Archive"
ChDrive "T"
ChDir MyPath

FileToOpen = Application.GetOpenFilename("Excel Files (*.xls), *.xls", ,
_
"Please select both previous and current weeks' Data Archives", , True)

If VarType(FileToOpen) < vbBoolean Then
For i = 1 To UBound(FileToOpen)
Set Wb = Workbooks.Open(FileToOpen(i))
Next
Else
'User canceled
Exit Sub
End If

End Sub



"FinChase" wrote in message
...
I am trying to open existing files in Excel. I am using the

GetOpenFilename
method to select the files.

Sub SelectBookToOpen()

Dim FileToOpen As Variant
Dim MyPath As String
Dim Wb As Workbook

MyPath = "T:\Archive"
ChDrive "T"
ChDir MyPath

FileToOpen = Application.GetOpenFilename("Excel Files (*.xls), *.xls",

, _
"Please select both previous and current weeks' Data Archives", ,

True)

If FileToOpen < False Then
Set Wb = Workbooks.Open(FileToOpen)
Else
Exit Sub
End If

End Sub

Everything works fine until I actually select a file and click Open. Then

I
get a data mismatch error on this line: If FileToOpen < False Then

What am I doing wrong?
Thanks, Lee



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Open existing file

That worked! Thanks for your help!

"PO" wrote:

Hi FinChase

If the user doesn't select a file, GetOpenFilename returns False (Boolean
value). If the user however selects one or more files GetOpenFilename
returns an array of variants.

Try this:

Sub SelectBookToOpen()

Dim FileToOpen As Variant
Dim MyPath As String
Dim Wb As Workbook
Dim i As Integer

MyPath = "T:\Archive"
ChDrive "T"
ChDir MyPath

FileToOpen = Application.GetOpenFilename("Excel Files (*.xls), *.xls", ,
_
"Please select both previous and current weeks' Data Archives", , True)

If VarType(FileToOpen) < vbBoolean Then
For i = 1 To UBound(FileToOpen)
Set Wb = Workbooks.Open(FileToOpen(i))
Next
Else
'User canceled
Exit Sub
End If

End Sub



"FinChase" wrote in message
...
I am trying to open existing files in Excel. I am using the

GetOpenFilename
method to select the files.

Sub SelectBookToOpen()

Dim FileToOpen As Variant
Dim MyPath As String
Dim Wb As Workbook

MyPath = "T:\Archive"
ChDrive "T"
ChDir MyPath

FileToOpen = Application.GetOpenFilename("Excel Files (*.xls), *.xls",

, _
"Please select both previous and current weeks' Data Archives", ,

True)

If FileToOpen < False Then
Set Wb = Workbooks.Open(FileToOpen)
Else
Exit Sub
End If

End Sub

Everything works fine until I actually select a file and click Open. Then

I
get a data mismatch error on this line: If FileToOpen < False Then

What am I doing wrong?
Thanks, Lee




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
How do I prevent Excel trying to open a non-existing file at start Jesperfect Excel Discussion (Misc queries) 0 May 15th 09 01:11 PM
User replaces existing file with blank during file open sjs Excel Discussion (Misc queries) 3 August 18th 08 06:16 PM
cannot open an existing file in excel 2003 chughes Excel Discussion (Misc queries) 3 March 2nd 07 12:46 PM
Can't open existing file LisaK Excel Discussion (Misc queries) 3 April 18th 06 10:14 PM
Open existing Excel file Bill Coupe Excel Discussion (Misc queries) 3 January 18th 05 07:53 PM


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