Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make Folder From Word Form Letter and Save Document In The Folder

Status
Not open for further replies.

moppdawg

Technical User
Mar 5, 2011
1
US
I would like to create a Word VBA code that will open a form letter. Then create a folder with a field reference in the name. Then save the active document in the new folder. I would also like to reference the same field in the document name. Something like "C:\My Documents\John Perry Conversion\John Perry Conversion Letter.doc"

Sub CreateFolder()
Dim strTempDirPath As String
Dim Folder
Dim myReturn
Dim My_Folder As String
Dim FileDesc As String


Folder = ActiveDocument.Bookmarks("Name").Range.Text
strTempDirPath = "C:\Documents and Settings\Mopp Dawg\Desktop\"

FileDesc = ActiveDocument.Bookmarks("Name").Range.Text & "Conversion Letter" & ".doc"


My_Folder = strTempDirPath
If Dir(strTempDirPath, vbDirectory) <> "" Then

myReturn = MsgBox("Folder """ & Folder & """ already exists. Open folder to view files?", _
vbInformation + vbYesNo)
If myReturn = 6 Then

On Error GoTo Error_Show_Input:

Shell "C:\WINDOWS\explorer.exe """ & My_Folder & "", vbNormalFocus
On Error GoTo 0

Exit Sub
On Error GoTo 0
Error_Show_Input:

MsgBox "Program can not open this folder." + Chr(13) + Chr(10) + "[" + Error(Err) + "]", vbOKOnly, "Error"
If myReturn = 7 Then Exit Sub
End If

Else
MkDir (strTempDirPath)

MsgBox ("File """ & Folder & """ has been created")

ActiveDocument.SaveAs "strTempDirPath" & FileDesc

End If

End Sub
 
You have some syntax errors there. Your IF..End IF do not match up correctly. But other than that, what exactly is your problem?

BTW: please use the code tags when posting code. See the "Process TGML" link.

55,687.00 hours down....
<60 hours to go

tick tick tick tick tick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top