jiggler
11-06-2008, 02:00 AM
Hello
I'm new to VBA and have been attempting to write a code in Word.
The code is intended to save the active file as its name plus 1. So i therefore have numbered incremental file names.
Then this saved file should be saved as the same file name but instead of the number in the file name it should say "Control". Thus replacing any previously saved files with this name. It should save one as a word doc and another as other as html
The problem i am having is that though i can get this code to work, i can only get it to work if i specify individual file names and paths. But i need the code to work on any file that i have open- what do i need to put in place of the file names and path?
Sub incrementedsavename2()
Dim PathAndFileName As String, n As Long
PathAndFileName = "h:\IAS STUFF\Change the file type\animals\elephant v"
PathAndFileName2 = "h:\IAS STUFF\Change the file type\animals\elephant CONTROL"
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
ActiveDocument.SaveAs PathAndFileName2 & ".htm"
ActiveDocument.SaveAs PathAndFileName2 & ".doc"
End Sub
I have searched the threads as well as other sites but cant find specifically what i'm looking for, can someone please help??
Thanks
Jiggler
I'm new to VBA and have been attempting to write a code in Word.
The code is intended to save the active file as its name plus 1. So i therefore have numbered incremental file names.
Then this saved file should be saved as the same file name but instead of the number in the file name it should say "Control". Thus replacing any previously saved files with this name. It should save one as a word doc and another as other as html
The problem i am having is that though i can get this code to work, i can only get it to work if i specify individual file names and paths. But i need the code to work on any file that i have open- what do i need to put in place of the file names and path?
Sub incrementedsavename2()
Dim PathAndFileName As String, n As Long
PathAndFileName = "h:\IAS STUFF\Change the file type\animals\elephant v"
PathAndFileName2 = "h:\IAS STUFF\Change the file type\animals\elephant CONTROL"
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
ActiveDocument.SaveAs PathAndFileName2 & ".htm"
ActiveDocument.SaveAs PathAndFileName2 & ".doc"
End Sub
I have searched the threads as well as other sites but cant find specifically what i'm looking for, can someone please help??
Thanks
Jiggler