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
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