jiggler
08-08-2007, 04:46 PM
Hey there newbie here,
I am quite new to VBA and have been trying to create a macro in word. The macro should always save the open document as its name with the new version number. For example: 'xxx v1', and if i use the macro again: 'xxx v2'. The macro will also save the document as a .htm file but will name it 'xxx', thus replacing the original .htm of the same name. Before it saves i want a form box to appear to prompt the user to type text in a specific area of the document. The text can be typed in the dialogue box and then when 'OK' is pressed the macro proceeds to save the document and name it as previously described.
Below is as far as i've got. The astute amongst you will realise that i have been unable to successfully include the form!
Also, the script i have only works for one document! (named 'test'). I need it to work for any document i open in Word.
Hope this makes sense, really need help:
Sub
ActiveDocument.SaveAs FileName:="test.htm", FileFormat:=wdFormatHTML, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
ActiveWindow.View.Type = wdWebView
Dim PathAndFileName As String, n As Long
PathAndFileName = "E:\macro tests\test v"
If Dir(PathAndFileName & ".doc") = "" Then
ActiveDocument.SaveAs (PathAndFileName & ".doc")
Else
n = 1
Do While Dir(PathAndFileName & n & ".doc") <> ""
n = n + 1
Loop
ActiveDocument.SaveAs PathAndFileName & n & ".doc"
End If
End Sub
Thanks
Jiggler
I am quite new to VBA and have been trying to create a macro in word. The macro should always save the open document as its name with the new version number. For example: 'xxx v1', and if i use the macro again: 'xxx v2'. The macro will also save the document as a .htm file but will name it 'xxx', thus replacing the original .htm of the same name. Before it saves i want a form box to appear to prompt the user to type text in a specific area of the document. The text can be typed in the dialogue box and then when 'OK' is pressed the macro proceeds to save the document and name it as previously described.
Below is as far as i've got. The astute amongst you will realise that i have been unable to successfully include the form!
Also, the script i have only works for one document! (named 'test'). I need it to work for any document i open in Word.
Hope this makes sense, really need help:
Sub
ActiveDocument.SaveAs FileName:="test.htm", FileFormat:=wdFormatHTML, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
ActiveWindow.View.Type = wdWebView
Dim PathAndFileName As String, n As Long
PathAndFileName = "E:\macro tests\test v"
If Dir(PathAndFileName & ".doc") = "" Then
ActiveDocument.SaveAs (PathAndFileName & ".doc")
Else
n = 1
Do While Dir(PathAndFileName & n & ".doc") <> ""
n = n + 1
Loop
ActiveDocument.SaveAs PathAndFileName & n & ".doc"
End If
End Sub
Thanks
Jiggler