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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create word file using VBA

Status
Not open for further replies.

Djackola

Technical User
Jan 31, 2011
7
I have a database with 5000 client records
I setup a button in my form to create a folder for a client using the first name,Surname and Id fields in specific location ( Source folder) and other one to view the created folder. ( both codes listed below).
I’m writing letters to those clients using word application and my problem when I want to save the word file in a the client folder it take long time to find the client folder.
Is any way to setup a code to let me to lunch a word document in a client folder and to be saved there automatically.


regards

Private Sub CreateFolder_Click()
Dim strname As String
Dim strfname As String
On Error GoTo 1
strname = MemberName
strfname = MemberFamilyName
MkDir "C:\Users\Moawia\Desktop\sOURCE\" & strname & " " & strfname & "__" & ID
MsgBox (strname & " " & strfname & "__" & ID & " has been created successfully")
Exit Sub
1 MsgBox ("Could not create folder for this Client " & vbNewLine & "Folder may created already or " & vbNewLine & "Please check the Client's name and Client's family name.")
End Sub



Private Sub ViewFolder_Click()
Dim strname As String
Dim strfname As String
Dim path As String

On Error GoTo 1
strname = MemberName
strfname = MemberFamilyName
path = "Explorer.exe C:\Users\Moawia\Desktop\sOURCE\"
folder = strname & " " & strfname & "__" & ID
filename = path & strname & " " & strfname & "__" & ID
If Dir("C:\mainData\" & folder, vbDirectory) <> "" Then
Shell (filename), vbMaximizedFocus
Else
MsgBox ("Folder not exist")
End If
Exit Sub
1 MsgBox ("Could not view folder for this Client, folder may not exist.")
End Sub


 
I jus put a thrad up with code that launches a word document. It has problem it not populating the bookmarks. But it may help you open the template you require and then save it to the correct directory with code above

Never give up never give in.

There are no short cuts to anything worth doing :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top