Click to See Complete Forum and Search --> : Call SaveAs option of windows
vipinkrsharma
Aug 24th, 2001, 04:18 PM
I want to save some html files using windows Save As option to "text file " type . Can any body suggest me is there any API to do that. I have not API's so please tell me how to use them also. Note : I want to use "Save As" beacuse it will not insert the HTML tags in between the file, as happen if you use "rename" cammand from command prompt.
vipinkrsharma@hotmail.com
DaveAMS
Aug 24th, 2001, 04:42 PM
Not exactly sure what you're trying to do...
I'm assuming that you're writing a vb program that will save an html file as a text file. There is an API call to open the "save as" dialog box: "GetSaveFileName." The details of how this function works are explained in the following URL, so I won't waste space here:
http://www.vbapi.com/ref/g/getsavefilename.html
Once you have the filename that you're saving to, you're going to need to either use the methods built into vb to write the data to that file, or you can use API calls for that also. Those API calls will be:
createfile: http://www.vbapi.com/ref/c/createfile.html
writefile: http://www.vbapi.com/ref/w/writefile.html
closehandle: http://www.vbapi.com/ref/c/closehandle.html
Once again, the details of these functions are explained very nicely on the listed pages.
Hope this helps...
Megatron
Aug 24th, 2001, 05:12 PM
Why not just use a CommonDialog box?
vipinkrsharma
Aug 24th, 2001, 06:52 PM
I dont want to use "Save As"dialog box to popup. CommonDialog will popup the dailogbox, which I dont want. Actaully I have some thousand of html file , which I want to convert into .txt file. Problem is if I use "rename" command , it rename the html file but add with html tags. But if "Save As" is use with text file type, it did not add those html tags with in file.
....Now I want to use that "save as" without prompting me the dailogbox. As in my case there are more than 5000 html file, so I cant afford to do it manually.
Am I clear now.................
vipinkrsharma
Aug 25th, 2001, 07:24 AM
Hi All,
I feel I need to reframe the question and make my problem more clearer......
My reqirement is I have some 5000 odd html files. I want to convert those html files to text files without html tags......
To do this manual process which I use is,
Step1 : Open that html file
Step2 : From the file option , use "Save As" to save it as text file
In this way I am able to get text form of that particular html file without html tags.
Now as I have more then 5000 html files and expecting more, I cant use this manual process.
So please suggest me some way to do it from VB itself.......
Thanx for ur help...
-Vipin
vipinkrsharma
Aug 29th, 2001, 10:20 PM
Can anyone help me please? Its kind of stucking me up and any help is greatly appreciated. I didnt hear from any of you...
Thanks
DaveAMS
Aug 30th, 2001, 07:59 AM
I misunderstood what you were trying to do. I'm a little surprised that someone hasn't already written a shareware/freeware app that can do this. Barring that, your best solution might be vba (visual basic for applications):
MS Word 2000 can read/edit html files. It also has vba, sort of a scaled down version of vb. You can program word to open each file sequentially, and then resave the file as a text document. This code should do what you want.
Sub Macro1()
Dim fName As String, curDoc As Document
ChDir ("C:\my documents\")
fName = Dir("*.htm")
Do While Len(fName) > 0
Set curDoc = Documents.Open(fName)
curDoc.SaveAs fName & ".txt", wdFormatDOSText
curDoc.Close
fName = Dir
Loop
End Sub
Disclaimer: I tried this on several different documents. If you have any scripts in the web page, the scripts are brought through into the text document. It also doesn't appear to handle stylesheets too well...I had some css data that came through in the text file also.
vipinkrsharma
Aug 30th, 2001, 12:16 PM
Thanx Dave for ur efforts, but ur solution didnt work for me .
After this statement ''fName = Dir("*.htm") '' , there is nothing in "fname" . Is there something missing in ur code, or I am doing some thing wrong.......
DaveAMS
Aug 30th, 2001, 12:52 PM
Two things to check:
First, make sure that you've changed to the correct directory. If you're actually looking for the files on a different drive (i.e. "d:\directory\"), you need to change drives first. Use the ChDrive command if necessary, and then use CurDir to check and make sure that you're in the directory that you think you are.
Second, make sure that your html files have a ".htm" extension. You may need to look for "*.html" instead.
Sub Macro1()
Dim fName As String, curDoc As Document
ChDrive ("c:\") 'Whatever Drive you want
ChDir ("C:\my documents\") 'whatever the path of the files is
debug.print CurDir 'should be "C:\my documents\"
fName = Dir("*.htm") 'May need to be "*.html"
Do While Len(fName) > 0
Set curDoc = Documents.Open(fName)
curDoc.SaveAs fName & ".txt", wdFormatDOSText
curDoc.Close
fName = Dir
Loop
End Sub
vipinkrsharma
Aug 30th, 2001, 01:41 PM
Hi Dave,
Thanx for ur concern......
Earlier "ChDrive ("c:\") " was missing , but still this "Set curDoc = Documents.Open(fName) " throwing this error "ActiveX component Cannot cerate object" .
Extension I had already changed to .html
Waiting for response......
DaveAMS
Aug 30th, 2001, 02:11 PM
ummm...I can't duplicate your error. I'm kind of at a loss, unless it has to do with a ms-word version issue.
I lied about my ms-word version...I'm using Word 97-sr1. (I forgot that I was on my work pc...they buy me visual studio 6.0 enterprise, and then give me ms-office 97. Go figure...)
I'll try it on word 2k tonight...maybe the document object model has changed. (You might check and make sure that the documents.open method hasn't changed. From the VBA Editor window, hit F2 to open the object browser. Select the Documents collection in the left pane, and the open method from the right pane, right click and choose help. It should give you all of the syntax for the statement. Make sure that it returns a document object, and that there is only one required parameter.)
vipinkrsharma
Aug 30th, 2001, 03:20 PM
Hi Dave ,
Every thing seems to be OK But I am not able to run the code . I am working on Win 2K and VB 6.0 .
Here is syntax I got .....
Function Open(FileName, [ConfirmConversions], [ReadOnly], [AddToRecentFiles], [PasswordDocument], [PasswordTemplate], [Revert], [WritePasswordDocument], [WritePasswordTemplate], [Format], [Encoding], [Visible]) As Document
Member of Word.Documents
I dont have complete MSDN installed , so I am not to get the exact example and syantax... I will try to get it form some where else. Mean while if u please get some thing please let me know.......
-Vipin
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.