[Office] Copieren van Word naar Excel met macro

Pagina: 1
Acties:

  • Rusty
  • Registratie: Juni 1999
  • Laatst online: 25-08 10:40
Ik probeer een word en een excel document te koppelen via een macro.

In het word document zit een userform waar informatie ingevoerd wordt. Deze informatie wordt vervolgens in een document (word) gebruikt om een standaard brief te maken.

Echter deze informatie moet ook in een excel sheet ingevuld worden, op dit moment gebeurt dat met de hand. Ik wil dit het liefst automatiseren met een macro.

Het gedeelte uit de word macro waar de waardes staan is dit:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
If bolOKButtonPressed Then

WordBasic.SetDocumentProperty "ProjectTitle", 0, UserForm1.ProjectTitle.Value, 2
WordBasic.SetDocumentProperty "PAnummer", 0, UserForm1.PAnummer.Value, 2
WordBasic.SetDocumentProperty "CompanyName", 0, UserForm1.CompanyName.Value, 2
WordBasic.SetDocumentProperty "CompanyStreet", 0, UserForm1.CompanyStreet.Value, 2
WordBasic.SetDocumentProperty "ZipCode", 0, UserForm1.ZipCode.Value, 2
WordBasic.SetDocumentProperty "CompanyCity", 0, UserForm1.CompanyCity.Value, 2
WordBasic.SetDocumentProperty "ContactPerson", 0, UserForm1.ContactPerson.Value, 2
WordBasic.SetDocumentProperty "PhoneNumberTech", 0, UserForm1.PhoneNumberTech.Value, 2

temp_InvoiceCompany = WordBasic.[GetDocumentProperty$]("InvoiceCompany")
temp_InvoiceStreet = WordBasic.[GetDocumentProperty$]("InvoiceStreet")
temp_ZipCodeInvoice = WordBasic.[GetDocumentProperty$]("ZipCodeInvoice")
temp_InvoiceCity = WordBasic.[GetDocumentProperty$]("InvoiceCity")
temp_ContactPersonInvoice = WordBasic.[GetDocumentProperty$]("ContactPersonInvoice")
temp_PhoneNumberInvoice = WordBasic.[GetDocumentProperty$]("PhoneNumberInvoice")
' temp_Conslevel0 = WordBasic.[GetDocumentProperty$]("Conslevel0")
temp_Conslevel1 = WordBasic.[GetDocumentProperty$]("Conslevel1")
temp_Conslevel2 = WordBasic.[GetDocumentProperty$]("Conslevel2")
temp_Conslevel3 = WordBasic.[GetDocumentProperty$]("Conslevel3")
temp_Conslevel4 = WordBasic.[GetDocumentProperty$]("Conslevel4")
temp_Conslevel5 = WordBasic.[GetDocumentProperty$]("Conslevel5")

' MsgBox ("temp_Conslevel1 is GetDocProp-Conslevel1")

' If UserForm1.Conslevel1.Value = temp_Conslevel1 Then
' WordBasic.SetDocumentProperty "Conslevel1", 0, Conslevel1.Value, 2
' Else
' WordBasic.SetDocumentProperty "Conslevel1", 0, UserForm1.Conslevel1.Value, 2
' End If

' MsgBox ("Conslevel1")

temp_hrrate1 = WordBasic.[GetDocumentProperty$]("hrrate1")
temp_hrrate2 = WordBasic.[GetDocumentProperty$]("hrrate2")
temp_hrrate3 = WordBasic.[GetDocumentProperty$]("hrrate3")
temp_hrrate4 = WordBasic.[GetDocumentProperty$]("hrrate4")
temp_hrrate5 = WordBasic.[GetDocumentProperty$]("hrrate5")


het gaat vooral om:
code:
1
2
3
4
5
temp_Conslevel1 = WordBasic.[GetDocumentProperty$]("Conslevel1")
temp_Conslevel2 = WordBasic.[GetDocumentProperty$]("Conslevel2")
temp_Conslevel3 = WordBasic.[GetDocumentProperty$]("Conslevel3")
temp_Conslevel4 = WordBasic.[GetDocumentProperty$]("Conslevel4")
temp_Conslevel5 = WordBasic.[GetDocumentProperty$]("Conslevel5")


Ik weet niet hoe ik hier een copy functie naar excel in kan krijgen.

Ik heb uiteraard al de search gebruikt maar kon niks vergelijkbaars vinden. Ook google heeft nog geen hulp geboden.

3 x Marstek Venus 5.12KW V151. CT003 V114 en HW P1


  • Rusty
  • Registratie: Juni 1999
  • Laatst online: 25-08 10:40
Een klein kickje in de hoop dat er iemand toch een idee heeft hoe dit te doen

3 x Marstek Venus 5.12KW V151. CT003 V114 en HW P1


  • F_J_K
  • Registratie: Juni 2001
  • Niet online

F_J_K

Moderator CSA/PB/AI

Front verplichte underscores

code:
1
2
3
4
5
6
7
8
9
10
11
12
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
Set xlWB = xlApp.Workbooks.Open("C:\foo.xls")

xlWB.Worksheets(1).Cells(2, 2) = "Woehoe, het werkt :P "

xlWB.Close True ' True om op te slaan, false is niet opslaan
xlApp.Quit
Set xlWB = Nothing
Set xlApp = Nothing

Aanpassen naar smaak :P

edit:

Er moet wel een referentie naar MS Excel zijn in Word: Invoegtoepassingen (oid) in de VBA-editor.

[ Voor 14% gewijzigd door F_J_K op 11-10-2004 10:41 ]

'Multiple exclamation marks,' he went on, shaking his head, 'are a sure sign of a diseased mind' (Terry Pratchett, Eric)