Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#357348 - 01/02/2013 23:01 VBA Help: Save As with a filter?
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31600
Loc: Seattle, WA
Please help!

Microsoft's online help and Google searches seem to go in circles here, and I keep coming back to the same set of contradictions.

I'm writing a Macro in Microsoft Word 2010. This macro must save a datafile that contains some comma delimited data, and prompt the user for the path and file name.

The following code:

Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogSaveAs)


Works, but it forces the extension to be ".docx". I want it to be my own extension, say ".foobar" or something. Ideally, I want the user to be able to type the file name and have it automatically add ".foobar" to the file name.

So, when I try to do this:

fd.Filters.Add "Foobar files", "*.foobar", 1

... VBA gives me an error that msoFileDialogSaveAs doesn't support filters.

Okay, fine, all the stuff on the web says that when I hit this problem, change it to a file picker dialog:

Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)


That's fine and the filters work at that point, but NOW THE USER CAN'T SAVE THE FILE!. The dialog picker only works if you PICK AN EXISTING FILE, and if the user types in their own file name, then there's a "sorry file does not exist error" and the user can't save the file.

When I try searching to find out how to "Save as" with msoFileDialogFilePicker, they all say either "it should work" (it doesn't) or they say to use msoFileDialogSaveAs instead, wash rinse repeat.

Someone please help me out of this vicious circle?

NOTE: suggestions to use something other than Word or VBA will not be helpful. This has to be coded in the Word for Windows Version 10 macro language in order for it to be useful.

How do I SAVE AS WITH FILTERS in the Word VBA macro language? Anyone know?
_________________________
Tony Fabris

Top
#357350 - 01/02/2013 23:10 Re: VBA Help: Save As with a filter? [Re: tfabris]
gbeer
carpal tunnel

Registered: 17/12/2000
Posts: 2665
Loc: Manteca, California
Ugly, but, Can you save it in a temp space as .docx then rename and move it.


Edited by gbeer (01/02/2013 23:11)
_________________________
Glenn

Top
#357352 - 01/02/2013 23:27 Re: VBA Help: Save As with a filter? [Re: tfabris]
gbeer
carpal tunnel

Registered: 17/12/2000
Posts: 2665
Loc: Manteca, California
Oops: forgot this is the file picker problem.

This example is for excel but it might work the same in word.

http://www.vbforums.com/showthread.php?4...l=1#post3075367

If I understand it. They are removing all the file extensions from the chooser and loading back in, only one they want.


Edited by gbeer (01/02/2013 23:30)
_________________________
Glenn

Top
#357353 - 01/02/2013 23:43 Re: VBA Help: Save As with a filter? [Re: gbeer]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31600
Loc: Seattle, WA
That's the one where, if I do it, it only lets the user select an existing file. The user can't save as to a new file name of their choosing. It tells them file not found.
_________________________
Tony Fabris

Top
#357354 - 02/02/2013 03:24 Re: VBA Help: Save As with a filter? [Re: tfabris]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3584
Loc: Columbus, OH
Does this help at all?
_________________________
~ John

Top
#357355 - 02/02/2013 03:52 Re: VBA Help: Save As with a filter? [Re: JBjorgen]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31600
Loc: Seattle, WA
Hm. Possibly. Calling the Windows API directly is certainly within my power, though messier than I'd normally want for this. If I can't find a solution in their scripting language, I'll resort to that. And that example shows how to do it in detail. THANKS!
_________________________
Tony Fabris

Top
#357384 - 04/02/2013 03:30 Re: VBA Help: Save As with a filter? [Re: tfabris]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3584
Loc: Columbus, OH
Originally Posted By: tfabris
Hm. Possibly. Calling the Windows API directly is certainly within my power, though messier than I'd normally want for this. If I can't find a solution in their scripting language, I'll resort to that. And that example shows how to do it in detail. THANKS!


I lived the hell of having Access (97 no less) as a primary developing platform for 10 years. In the end, we ended up with most of that kinda stuff calling the API directly because VBA just doesn't give enough control. If you wrap it up nicely enough, it becomes just as simple and easy to use as the built in stuff.
_________________________
~ John

Top
#357446 - 06/02/2013 21:44 Re: VBA Help: Save As with a filter? [Re: JBjorgen]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31600
Loc: Seattle, WA
Originally Posted By: JBjorgen
Does this help at all?


Implemented. Works.

Had to tweak the code in a couple of places where it was Access-specific, of course. But after that, works like a charm. THANKS!
_________________________
Tony Fabris

Top
#357458 - 07/02/2013 04:29 Re: VBA Help: Save As with a filter? [Re: tfabris]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3584
Loc: Columbus, OH
smile Still trying to work off that lunch you bought me in Seattle...
_________________________
~ John

Top