View Full Version : Getting information in userform word with combobox out of excel
felix85
03-23-2009, 03:45 AM
Hello People,
My englisch is not that good, so I hope somebody can help me.
1) I've got an excel file that contains information (adres, Location, name, etc.)
2) There is an Word.dot file that contains an Userform1 with an combobox(listbox).
My qeustions are:
- If I can open that word.dot with an commandbutton in an exceluserform and that he opens an new word file with that template as begin (fundament)..
- If I can get the information from excel ColumnB: "Zoeken" (thats the first cellname in that column) into the combobox(listbox)?
- When I select an name in the combobox that he puts the other information from that row in the Word.dot with bookmarks.
I Hope somebody can help me, because in the forums in the netherlands they can't help me.
Frendly greetz,
Felix
felix85
03-23-2009, 05:28 AM
Please somebody?? I need You're help..
fumei
03-23-2009, 10:51 AM
What code have you got so far?
Yes, while you are in Excel, you can clone a new Word document from a template. You need to create an instance of Word first of course.
Once you have the new document, yes, you can take data from the Excel file, and put it in a bookmark in the new document - assuming it has that bookmark.
felix85
03-24-2009, 12:26 AM
Hello Fumei,
Thank you for your reaction,
I've got the next codes:
The next code is in Excel Userform under the button Word.dot, I think one fold is that I open .dot and have to open .doc! Because he opens now the template, but when I make the code .doc he can't open the file!!
Application.ScreenUpdating = False
Dim oWdObj
Set oWdObj = CreateObject("Word.Application")
oWdObj.Visible = True
oWdObj.Documents.Open "I:\Medewerkers\Tom\Programma\Opdrachtverstrekking brief.dot"
Set oWdObj = Nothing
frmstartscherm.Hide
Sheets("Gebouwen").Select
Application.ScreenUpdating = True
The next code is in Word: this document
Private Sub Document_Open()
UserForm1.Show
End Sub
The next code is in Word: under the userform
Private Sub CommandButton1_Click()
Set Conn = CreateObject("ADODB.Connection")
Set RS = CreateObject("ADODB.Recordset")
Conn.Open "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=" & ActiveDocument.Path & "\Gegevens Gulpen-Wittem.xls;"
RS.Open "SELECT * FROM [Sheet1$] WHERE Rubriek = '" & ComboBox1 & "'", Conn
Selection.GoTo wdGoToBookmark, , , "Naam"
Selection.TypeText RS("Naam")
Selection.GoTo wdGoToBookmark, , , "Contact"
Selection.TypeText RS("Aanhef") & " " & RS("Contact")
Selection.GoTo wdGoToBookmark, , , "Adres"
Selection.TypeText RS("Adres")
Selection.GoTo wdGoToBookmark, , , "Postcode"
Selection.TypeText RS("Postcode en plaats")
Selection.GoTo wdGoToBookmark, , , "Geachte"
Selection.TypeText RS("Geachte") & " " & RS("Contact")
End Sub
____________________________________________________
Private Sub UserForm1_Initialize()
Set Conn = CreateObject("ADODB.Connection")
Set RS = CreateObject("ADODB.Recordset")
Conn.Open "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=" & ActiveDocument.Path & "\Gegevens Gulpen-Wittem.xls;"
RS.Open "SELECT * FROM [Sheet1$]", Conn
Do While Not RS.EOF
ComboBox1.AddItem RS("Rubriek")
RS.MoveNext
Loop
RS.Close: Set RS = Nothing
Conn.Close: Set Conn = Nothing
End Sub
Can somebody help me please?!?
Thanks alot mates
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.