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?
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?
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
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
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
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
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
Thank you so much!!!!