A
andrewwinters
I have code for using a click button in an Access form to take data from the
form, open a series of Word templates and insert data from the form into the
template bookmarks. I also can create a new folder, using data from the
Access form. But I'm getting stuck trying to then save the newly created
Word documents into the new folder. Instead it saves into MyDocuments. This
is a basic version of what the Code looks like:
Private Sub CreateDocuments_Click()
Dim Wrd As New Word.Application
Set Wrd = CreateObject("Word.Application")
Wrd.Documents.Add "C:\Documents and Settings\asw\My
Documents\appearance.dot"
Wrd.Visible = True
With Wrd.ActiveDocument.Bookmarks
.Item("County").Range.Text = County
.Item("State").Range.Text = State
End With
Dim newfol As String
newfol = County
MkDir (newfol)
Dim strSaveName As String
strSaveName = State
Wrd.ActiveDocument.SaveAs strSaveName
I can't now save the document into the newly created folder, which in this
example is named after the Access "County" bookmark. When I try
ChangeFileOpenDirectory _
"C:\Documents and Settings\asw\My Documents\County\"
I get an error not recognizing the new folder (even though when I check
later, the folder was, in fact, created).
Same thing when I try
ChangeFileOpenDirectory _ "C:\Documents and Settings\asw\My
Documents\newfol\"
Any suggestions? Thanks!
Wrd.ActiveDocument.Close
End Sub
form, open a series of Word templates and insert data from the form into the
template bookmarks. I also can create a new folder, using data from the
Access form. But I'm getting stuck trying to then save the newly created
Word documents into the new folder. Instead it saves into MyDocuments. This
is a basic version of what the Code looks like:
Private Sub CreateDocuments_Click()
Dim Wrd As New Word.Application
Set Wrd = CreateObject("Word.Application")
Wrd.Documents.Add "C:\Documents and Settings\asw\My
Documents\appearance.dot"
Wrd.Visible = True
With Wrd.ActiveDocument.Bookmarks
.Item("County").Range.Text = County
.Item("State").Range.Text = State
End With
Dim newfol As String
newfol = County
MkDir (newfol)
Dim strSaveName As String
strSaveName = State
Wrd.ActiveDocument.SaveAs strSaveName
I can't now save the document into the newly created folder, which in this
example is named after the Access "County" bookmark. When I try
ChangeFileOpenDirectory _
"C:\Documents and Settings\asw\My Documents\County\"
I get an error not recognizing the new folder (even though when I check
later, the folder was, in fact, created).
Same thing when I try
ChangeFileOpenDirectory _ "C:\Documents and Settings\asw\My
Documents\newfol\"
Any suggestions? Thanks!
Wrd.ActiveDocument.Close
End Sub