Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default GetSaveAsFilename Troubles

Hello all,

I've been fighting with this for too long now, have searched the web
and groups and now come seeking your assistance.

I'm running XL2003 on XP Home.

As presented below, this snippet of code generates a runtime error 13,
type mismatch. On debug, it stops on this line:
If vFileSaveName < False Then

Hovering over the vFileSaveName shows a value of Error 2015.

Here's the kicker: if you take out the Excel 2007 line, it works just
fine. I actually have a few more file types I want to add. So I'm
wondering if there's a limit to the length of the filefilter parameter
or something. That doesn't make sense though because XL's own Save As
has much more than this (unless that's really a different dialog that
looks the same...)

I appreciate any and all help to get me over this hurdle. Completely
different alternate solutions are of course welcome as well.

Thanks,
Kruncher

Dim vSaveFileFilter As Variant
Dim vInitFile As Variant
Dim vTitle As Variant

'These are declared earlier in the module
' Dim fd As FileDialog
' Dim vFileSaveName As Variant

vTitle = "Select the export file to use."
vInitFile = ""

' this fails with run-time error 13 type mismatch
vSaveFileFilter = "Lotus 1-2-3 rel 1 (*.wks), *.wks, " & _
"Lotus 1-2-3 rel 2 (*.wk1), *.wk1, " & _
"Lotus 1-2-3 rel 3 (*.wk3), *.wk3, " & _
"Microsoft Excel (*.xls), *.xls, " & _
"Microsoft Excel 2007 (*.xlsx), *.xlsx, " & _
"Microsoft Access (*.mdb), *.mdb, " & _
"Paradox (*.db), *.db, " & _
"Web Page (*.htm;*.html), *.htm;*.html, " & _
"Adobe PDF (*.pdf), *.pdf"

vFileSaveName = _
Application.GetSaveAsFilename(vInitFile,
vSaveFileFilter, 1, vTitle)


If vFileSaveName < False Then
GetFileName = vFileSaveName
End If
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default GetSaveAsFilename Troubles

You have to specify the file format for xl 2007 files.

http://www.rondebruin.nl/saveas.htm

Cliff Edwards

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default GetSaveAsFilename Troubles

You should dim your strings as strings also. If they're empty, they're
still strings, and you can still test for that.

What are you doing with getfilename?

Cliff Edwards
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default GetSaveAsFilename Troubles

On Jun 7, 7:20*pm, ward376 wrote:
You have to specify the file format for xl 2007 files.

http://www.rondebruin.nl/saveas.htm

Cliff Edwards


Thanks for the lead Cliff, but I'm not actually trying to save the
file, so I'm having some trouble trying to see how Ron's example
applies. I'm just want to use the dialog so that the user can navigate
easily, and select an existing file or supply a new file name.

The file name returned by the dialog will be used for another purpose.

In addition to the xlsx extension, I also want to make *.dbf, *.txt,
*.* (anything) and a couple of others as well, available choices for
the user.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default GetSaveAsFilename Troubles

On Jun 7, 7:28*pm, ward376 wrote:
You should dim your strings as strings also. If they're empty, they're
still strings, and you can still test for that.

What are you doing with getfilename?

Cliff Edwards


I did have them initially declared as strings, but since the online
helps says they're Variant, I changed them.

In fact, I initially had it built the call using the
[parameter]:=[value] format. Same difference.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default GetSaveAsFilename Troubles

I think you should be using getopenfilename rather than
getsaveasfilename. The syntax is the same. You're getting a file name
then doing stuff with it?

Cliff Edwards
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default GetSaveAsFilename Troubles

On Jun 7, 7:38*pm, ward376 wrote:
I think you should be using getopenfilename rather than
getsaveasfilename. The syntax is the same. You're getting a file name
then doing stuff with it?

Cliff Edwards


Essentially, yes. Can the user specify a new name with
GetOpenFilename, or are you limited to selecting from existing files?
I know I can try it out (and will, thanks) but if you know for sure,
then that's great.
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default GetSaveAsFilename Troubles

On Jun 7, 7:38*pm, ward376 wrote:
I think you should be using getopenfilename rather than
getsaveasfilename. The syntax is the same. You're getting a file name
then doing stuff with it?

Cliff Edwards


I just tried changing the call to:
vFileSaveName = Application.GetOpenFilename(vSaveFileFilter, 1,
vTitle, False)

Yielded exactly the same error. Very, very wierd.
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default GetSaveAsFilename Troubles


My guess is that you are up against a limit on the string length.
If the length of vSaveFileFilter is under 255 the dialog is displayed.
Add the line "MsgBox Len(vSaveFileFilter)" and see what you get.
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Kruncher"
wrote in message
Hello all,
I've been fighting with this for too long now, have searched the web
and groups and now come seeking your assistance.
I'm running XL2003 on XP Home.
As presented below, this snippet of code generates a runtime error 13,
type mismatch. On debug, it stops on this line:
If vFileSaveName < False Then
Hovering over the vFileSaveName shows a value of Error 2015.
Here's the kicker: if you take out the Excel 2007 line, it works just
fine. I actually have a few more file types I want to add. So I'm
wondering if there's a limit to the length of the filefilter parameter
or something. That doesn't make sense though because XL's own Save As
has much more than this (unless that's really a different dialog that
looks the same...)
I appreciate any and all help to get me over this hurdle. Completely
different alternate solutions are of course welcome as well.
Thanks,
Kruncher

Dim vSaveFileFilter As Variant
Dim vInitFile As Variant
Dim vTitle As Variant

'These are declared earlier in the module
' Dim fd As FileDialog
' Dim vFileSaveName As Variant

vTitle = "Select the export file to use."
vInitFile = ""

' this fails with run-time error 13 type mismatch
vSaveFileFilter = "Lotus 1-2-3 rel 1 (*.wks), *.wks, " & _
"Lotus 1-2-3 rel 2 (*.wk1), *.wk1, " & _
"Lotus 1-2-3 rel 3 (*.wk3), *.wk3, " & _
"Microsoft Excel (*.xls), *.xls, " & _
"Microsoft Excel 2007 (*.xlsx), *.xlsx, " & _
"Microsoft Access (*.mdb), *.mdb, " & _
"Paradox (*.db), *.db, " & _
"Web Page (*.htm;*.html), *.htm;*.html, " & _
"Adobe PDF (*.pdf), *.pdf"

vFileSaveName = _
Application.GetSaveAsFilename(vInitFile,
vSaveFileFilter, 1, vTitle)


If vFileSaveName < False Then
GetFileName = vFileSaveName
End If
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default GetSaveAsFilename Troubles

This should work for you.

Sub openas()
Dim vOpenFileFilter As String
Dim vTitle As String
Dim GetFileName As String
Dim vFileOpenName

vTitle = "Select the export file to use."
vOpenFileFilter = "All files(*.*), *.*"

vFileOpenName = _
Application.GetOpenFilename(vOpenFileFilter, 5, vTitle)

If vFileOpenName = "" Then
Exit Sub
Else
GetFileName = vFileOpenName
End If
End Sub

Cloiff Edwards


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default GetSaveAsFilename Troubles

On Jun 7, 7:56*pm, ward376 wrote:
This should work for you.

Sub openas()
Dim vOpenFileFilter As String
Dim vTitle As String
Dim GetFileName As String
Dim vFileOpenName

* * vTitle = "Select the export file to use."
* * vOpenFileFilter = "All files(*.*), *.*"

* * vFileOpenName = _
* * * * Application.GetOpenFilename(vOpenFileFilter, 5, vTitle)

* * If vFileOpenName = "" Then
* * * * Exit Sub
* * * * Else
* * * * GetFileName = vFileOpenName
* * End If
End Sub

Cloiff Edwards


The problem with the *.* fallback is that only certain file types are
to be permitted based on other prior logic in the program. One choice
should make the above files types available, other choices would make
only *.txt, *.ac, and *.pdf legal choices. Luckily those shorter
filters seem to work just fine.

Yes, *.* is one of the types allowed in this specific case, but I
still want to make it easy for the user to locate a particular file
type and this dialog should allow for that.

I do appreciate your attention to this. It's great to "talk" this over
with someone.

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default GetSaveAsFilename Troubles

Thanks Jim. yeah, the string that works OK is 252, so if I add
anything... boom.

Of course, there's no mention of a limit in the help (that I could
find).

So any ideas on where am I going next to do this?

On Jun 7, 7:56*pm, "Jim Cone" wrote:
My guess is that you are up against a limit on the string length.
If the length of vSaveFileFilter is under 255 the dialog is displayed.
Add the line "MsgBox Len(vSaveFileFilter)" and see what you get.
--
Jim Cone
Portland, Oregon *USAhttp://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default GetSaveAsFilename Troubles

Abbreviate the string...
vSaveFileFilter = "Lotus 1-2-3 rel 1 (*.wks), *.wks, " & _
"Lotus 1-2-3 rel 2 (*.wk1), *.wk1, " & _
"Lotus 1-2-3 rel 3 (*.wk3), *.wk3, " & _
"Excel (*.xls), *.xls, " & _
"Excel 2007 (*.xlsx), *.xlsx, " & _
"Access (*.mdb), *.mdb, " & _
"Paradox (*.db), *.db, " & _
"Web (*.htm;*.html), *.htm;*.html, " & _
"PDF (*.pdf), *.pdf"
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"Kruncher"
wrote in message
Thanks Jim. yeah, the string that works OK is 252, so if I add
anything... boom.
Of course, there's no mention of a limit in the help (that I could find).
So any ideas on where am I going next to do this?




On Jun 7, 7:56 pm, "Jim Cone"
wrote:
My guess is that you are up against a limit on the string length.
If the length of vSaveFileFilter is under 255 the dialog is displayed.
Add the line "MsgBox Len(vSaveFileFilter)" and see what you get.
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default GetSaveAsFilename Troubles

You're right, to use a new file name, you have to use
getsaveasfilename. I thought you were processing an existing file.
Jim is right also, if you add any more to the filefilter string
regardless of filetype it fails in the same place.

Cliff Edwards
  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default GetSaveAsFilename Troubles

On Jun 7, 8:29*pm, "Jim Cone" wrote:
Abbreviate the string...
vSaveFileFilter = "Lotus 1-2-3 rel 1 (*.wks), *.wks, " & _
* * * * * * * * * * * * "Lotus 1-2-3 rel 2 (*.wk1), *.wk1, " & _
* * * * * * * * * * * * "Lotus 1-2-3 rel 3 (*.wk3), *.wk3, " & _
* * * * * * * * * * * * "Excel (*.xls), *.xls, " & _
* * * * * * * * * * * * "Excel 2007 (*.xlsx), *.xlsx, " & _
* * * * * * * * * * * * "Access (*.mdb), *.mdb, " & _
* * * * * * * * * * * * "Paradox (*.db), *.db, " & _
* * * * * * * * * * * * "Web (*.htm;*.html), *.htm;*.html, " & _
* * * * * * * * * * * * "PDF (*.pdf), *.pdf"
--
Jim Cone
Portland, Oregon *USAhttp://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

"Kruncher"
wrote in message
Thanks Jim. yeah, the string that works OK is 252, so if I add
anything... boom.
Of course, there's no mention of a limit in the help (that I could find).
So any ideas on where am I going next to do this?

On Jun 7, 7:56 pm, "Jim Cone"
wrote:



My guess is that you are up against a limit on the string length.
If the length of vSaveFileFilter is under 255 the dialog is displayed.
Add the line "MsgBox Len(vSaveFileFilter)" and see what you get.
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)- Hide quoted text -


- Show quoted text -


Thanks guys. If nothing else, I'm glad my suspicion on the filter
length was confirmed.

I'll need to compromise with the less than optimal, but functional:
sSaveFileFilter = "Lotus 123 v1 (*.wks), *.wks, " & _
"123 v2 (*.wk1), *.wk1, " & _
"123 v3 (*.wk3), *.wk3, " & _
"MS XL (*.xls;*.xlsx), *.xls;*.xlsx, " & _
"Paradox (*.db), *.db, " & _
"Text (*.*), *.*, " & _
"MS Access (*.mdb), *.mdb, " & _
"dBase (*.dbf), *.dbf, " & _
"Web (*.htm;*.html), *.htm;*.html, " & _
"PDF (*.pdf), *.pdf"

That's the full set. Squeaks in at 250 characters. All that
duplication of the extensions eats up space! They couldn't have coded
it so that you only need to supply an extension once?!?!

Thanks again. Really and sincerely appreciated. On to the rest of the
it now...


  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default GetSaveAsFilename Troubles

Do your users ever use existing files?
  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default GetSaveAsFilename Troubles

On Jun 7, 9:20*pm, ward376 wrote:
Do your users ever use existing files?


Don't know; it's possible. Brand new application. Why? What do you
have in mind?
  #18   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default GetSaveAsFilename Troubles

Well, I was thinking you could use your own dialog or even an input
box to get a file name. If you're users may use existing files, or you
want them to be able to easily modify existing filenames for use, this
could get way complex, especially with all the file types and
potential paths.

If you decide to go this way, you might be interested in these links
on Chip Pearson's site:
http://www.cpearson.com/excel/FolderTreeView.aspx
http://www.cpearson.com/excel/FolderTree.aspx

I haven't tried them so I don't know if there's a limit on include or
exclude file types string lengths.

Cliff Edwards








  #19   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default GetSaveAsFilename Troubles

I'll check it out. Thanks for your continued interest and assistance
Cliff.

On Jun 9, 8:03*am, ward376 wrote:
Well, I was thinking you could use your own dialog or even an input
box to get a file name. If you're users may use existing files, or you
want them to be able to easily modify existing filenames for use, this
could get way complex, especially with all the file types and
potential paths.

If you decide to go this way, you might be interested in these links
on Chip Pearson's site:http://www.cpearson.com/excel/Folder...olderTree.aspx

I haven't tried them so I don't know if there's a limit on include or
exclude file types string lengths.

Cliff Edwards


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
Help with getsaveasfilename Jo Excel Discussion (Misc queries) 2 June 5th 07 12:41 AM
GetSaveAsFilename Syed Zeeshan Haider Excel Programming 2 December 8th 06 06:53 PM
Help with GetSaveAsFilename aj Excel Programming 0 March 23rd 06 08:32 PM
GetSaveasFileName Libby Excel Programming 1 September 8th 05 07:45 PM
GetSaveAsFilename Anand Attavane Excel Programming 2 October 22nd 03 01:21 AM


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