Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to save a MS-Word file using Common Dialog Box 1

Status
Not open for further replies.

dipankar

Programmer
Aug 8, 2001
6
IN
Hello,
I am writing on a MS-Word file and want to Save it as a different filename using Save As Common Dialog Box. How should i do it ? I have already shown the dialog box using .ShowOpen commands but i can't save the file according to my choice of the name specified.
Please Help!!!

Thanx ,
Dipankar
 
Hi,

Could you give some more information? Are you using a word object to open the word file, or have you opened the file as a text file (by using: Open file for output as #1)?

 
Hi PainKiller,
i am opening the word file with a word object as Word.Application and Word.Documents. Infact, i am opening a doc file called "dipankar", making some changes in it with replace function , and then i want to save it as a word file with the name i specify. At this point i am stuck. I can't save the file ):

Can u help?

Thx a lot
Dipankar
 
Hi Dipankar,

Here's how you do it:

Private wdApp As Word.Application

Set wdApp = New Word.Application
set wdApp.visible = false 'do not show Wordobject

'strDoc = "Dipankar.doc"
wdApp.Documents.Open strDoc

'strYourFile contains the filename you want to save it as
wdApp.Documents.SaveAs strYourFile

'if you want to convert the file, say to html or txt format
'use this code

wdApp.Documents.SaveAs strYourFile, wdFormatHTML
wdApp.Documents.SaveAs strYourFile, wdFormatText

wdApp.ActiveDocument.Close 'close the document

'don't forget to use the quit method, or else the Word
'object will stay in your system memory, when u open a lot
'of word objects, this can lead to memeory failures!!

wdApp.Quit
Set wdApp = Nothing 'destroy the object

Hope this helps.
 
Hi PainKiller,

from this i could not get how to use the CommonDialog box to Save this file which is my major concern.
Do u have any solutions as such?

Thx a lot
Dipankar
 
Set wdApp = New Word.Application
wdApp.Visible = False 'do not show Wordobject

strdoc = "dipankar.doc"
wdApp.Documents.Open strdoc

'set the filter, this means that u specify the extension which will be set in
'the variable strFileName
CommonDialog1.Filter = "Word documents (*.doc)|*.doc"

'show the save dialog
CommonDialog1.ShowSave

'get the selected path + name
strSaveFile = CommonDialog1.FileName


'strYourFile contains the filename you want to save it as
wdApp.ActiveDocument.SaveAs FileName:=strSaveFile, FileFormat:=wdFormatDocument

'if you want to convert the file, say to html or txt format
'use this code
'wdApp.Documents.SaveAs Str, wdFormatHTML
'wdApp.Documents.SaveAs strYourFile, wdFormatText

wdApp.ActiveDocument.Close 'close the document

'don't forget to use the quit method, or else the Word
'object will stay in your system memory, when u open a lot
'of word objects, this can lead to memeory failures!!

wdApp.Quit
Set wdApp = Nothing 'destroy the object

 
forgot to mention with my latest reply, if you want ot convert the doc file to another type of file (txt, html) you will have to put in code that removes the extenstion from the strSaveFile, or else you will wind up with files such as : dipankar.doc.txt or dipankar.doc.html

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top