Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
GetSaveAsFilename Troubles
You have to specify the file format for xl 2007 files.
http://www.rondebruin.nl/saveas.htm Cliff Edwards |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
GetSaveAsFilename Troubles
Do your users ever use existing files?
|
#17
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Help with getsaveasfilename | Excel Discussion (Misc queries) | |||
GetSaveAsFilename | Excel Programming | |||
Help with GetSaveAsFilename | Excel Programming | |||
GetSaveasFileName | Excel Programming | |||
GetSaveAsFilename | Excel Programming |