PDA

View Full Version : Solved: Save as



jperry
03-17-2005, 07:09 AM
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... :bug:

Anyone?

mvidas
03-17-2005, 07:14 AM
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:
ActiveDocument.SaveAs FileName:="filename.htm", FileFormat:=wdFormatHTML

Matt

jperry
03-17-2005, 07:29 AM
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...:think:

sandam
03-17-2005, 07:39 AM
this should work

SaveAs FileName:=ActiveDocument.FileName + ".htm", FileFormat:=wdFormatHTML

mvidas
03-17-2005, 07:41 AM
That definately makes sense. You could either use code like:
ActiveDocument.SaveAs FileName:=ActiveDocument.Path & "\" & Left(ActiveDocument.Name, _
Len(ActiveDocument.Name) - 4) & ".htm", FileFormat:=wdFormatHTML
Or to use string variables, so you can see where/what it is being named, you could try:
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

Matt

sandam
03-17-2005, 08:01 AM
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.

jperry
03-17-2005, 08:02 AM
Thank you so much!!!! :thumb