Results 1 to 12 of 12

Thread: Call SaveAs option of windows

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    34

    Red face Call SaveAs option of windows

    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.


    [email protected]
    Last edited by vipinkrsharma; Aug 24th, 2001 at 06:42 PM.

  2. #2
    Lively Member
    Join Date
    Aug 2001
    Location
    Crossroads of America
    Posts
    72
    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...

  3. #3
    Megatron
    Guest
    Why not just use a CommonDialog box?

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    34

    Call SaveAs option of windows

    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.................

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    34

    reframing the question

    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

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    34

    Please help me!!!!!

    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

  7. #7
    Lively Member
    Join Date
    Aug 2001
    Location
    Crossroads of America
    Posts
    72
    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.

  8. #8

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    34

    Solution didnt work for me

    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.......

  9. #9
    Lively Member
    Join Date
    Aug 2001
    Location
    Crossroads of America
    Posts
    72
    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

  10. #10

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    34

    Again something is missing

    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......

  11. #11
    Lively Member
    Join Date
    Aug 2001
    Location
    Crossroads of America
    Posts
    72
    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.)

  12. #12

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    34
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width