Create INI file; save to user selected location

E

Ed

I want to save an INI file to a user selected location. I need to automate
the process with VBA.

I have read the data I want from the registry and placed it onto my editing
screen. I want the user to navigate to the folder to store the file and save
it as 'MyINIFile.ini'.

With Dialogs(wdDialogFileSaveAs)
.name = "MyINIFile.ini"
CloseNum = .Display
End With

When the above runs, Word forces me into a doc file.

When I change to this:

With Dialogs(wdDialogFileSaveAs)
.name = "XXXXX.ini"
.Format = wdFormatDOSTextLineBreaks
CloseNum = .Display
End With

Word forces me into a .txt file. No option exists for INI.

Any way to allow an INI file extension (and not confuse the user)? (Note
that I use '.Display' not show. That way I can at least get a user to
navigate to the proper folder, capture the path and behind the scenes save
the proper file, but that is really confusing to the user who will think he
has saved a txt file.)

Ed (in Virginia)
 
D

Doug Robbins - Word MVP

An .ini file is just a text file with a particular structure. However,
perhaps you should use System.PrivateProfileString

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
E

Ed

I may have misled you on my need. It really isn't the creating an ini file
(qua ini file) that I need, but rather the ability to save a file with a
non-standard extension. I was using 'ini' as an example, but it could have
been '.abc' or '.xyz.

Is there any way to get Word to allow a non-standard extension in the SaveAs
routine.

Sorry for the confusion.

Ed (in Virginia)
 
J

Jonathan West

Ed said:
I may have misled you on my need. It really isn't the creating an ini file
(qua ini file) that I need, but rather the ability to save a file with a
non-standard extension. I was using 'ini' as an example, but it could have
been '.abc' or '.xyz.

Is there any way to get Word to allow a non-standard extension in the
SaveAs routine.

Sorry for the confusion.

By default, Windows doesn't display the filename extension in Windows
Explorer. When Windows explorer is set up that way, all other dialogs follow
suit, and Word works on the assumption that the extension must always be
added to the end of the filename, unless the filename displayed in the
dialog already ends with the correct extension, in which case it is not
duplicated.

In order to get round this, you need instead to use the FileDialog object.
Use this to get the user to choose the filename and folder into which the
file will be saved. Then you modify the filename as necessary to ensure that
the extension you want is included. Then use the SaveAs method to save the
file, passing to it the full pathname where you want to the file to be ased.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top