Consulting

Results 1 to 7 of 7

Thread: Solved: Save as

  1. #1
    VBAX Regular
    Joined
    Mar 2005
    Posts
    8
    Location

    Solved: Save as

    Hello again. I am trying to figure out how to make a macro that will save a text file as an htm file or the same function as

    File
    Save As Web Page

    I've looked all over for help on this...

    Anyone?

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Hi jperry,

    The best thing to do, while trying to get code that performs a function in the program, is to record your own macro. Go to Tools, Macro, Record, save the file as a web page, then stop recording. Your code will do what you need, and should look something like:
    [vba] ActiveDocument.SaveAs FileName:="filename.htm", FileFormat:=wdFormatHTML[/vba]

    Matt

  3. #3
    VBAX Regular
    Joined
    Mar 2005
    Posts
    8
    Location

    Cool

    Cool, okay. I got that part...

    Is there a way to do this...

    where

    FileName:=" filename.htm"

    I want to be able to use the filename of the file I am currently working on...the way it works now is, it saves it as the same filename everytime. Is there a way to do this? Hope that made sense.

    Example: When I recored the macro, it saved the filename as test.htm Every document I open and run this macro on it saves as test.htm
    I have about 20 documents that I have to edit...but I need to save them with their original name.htm
    Like: opened test1.txt need to save as test1.htm
    test2.txt test2.htm

    etc...
    I hope I explained that ok...
    Last edited by jperry; 03-17-2005 at 07:43 AM. Reason: clarification

  4. #4
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    this should work

    [vba]SaveAs FileName:=ActiveDocument.FileName + ".htm", FileFormat:=wdFormatHTML[/vba]
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  5. #5
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    That definately makes sense. You could either use code like:
    [vba] ActiveDocument.SaveAs FileName:=ActiveDocument.Path & "\" & Left(ActiveDocument.Name, _
    Len(ActiveDocument.Name) - 4) & ".htm", FileFormat:=wdFormatHTML[/vba]
    Or to use string variables, so you can see where/what it is being named, you could try:
    [vba] Dim fPath As String, fName As String, sName As String
    fPath = ActiveDocument.Path
    fName = ActiveDocument.Name
    sName = fPath & "\" & Left(fName, Len(fName) - 4) & ".htm"
    ActiveDocument.SaveAs FileName:=sName, FileFormat:=wdFormatHTML[/vba]

    Matt

  6. #6
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    Oops, I forgot the file path, sorry :$. If you don't use file path then it saves to the default directory which is "My Documents" unless you change it yourself in the settings. The only thing I'm wondering is if you leave the ".htm" off, will it still add the suffix if the fileformat is set to wdFormatHTML? I know it does it for word docs (".doc") althoght they are the default file type.
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  7. #7
    VBAX Regular
    Joined
    Mar 2005
    Posts
    8
    Location

    Smile It Worked!!!

    Thank you so much!!!!

Posting Permissions

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