IkEcht
12-07-2012, 06:48 AM
Hi all,
I'm trying to do a lot of find and replace operations in word, using word vba. Getting the text to find from an excel file, as well as the replacing text.
It is in the replacing text that I have a problem. I want to be able to use code in there. So for instance replace the text Yearnow by Year(date). All of this works fine when done from within word only, but getting the data from within excel makes it malfunction. For instance in the code below even though the word "gemeente" is taken from excel, this is not replaced by "test" . Any ideas on how to solve this?
Sub vervangmaarvanuitexcel()
Dim zoek As String
Dim vervang As String
Dim vervang2 As Variant
Dim i As Integer
Dim wb As Excel.Workbook
gemeente = "test"
Set xl = CreateObject("Excel.Application")
xl.Workbooks.Open "Q:\635 Netwerkanalyse\1 - Projectdocumenten\rapportage\dummyzoekenvervang.xlsx"
i = 2
Do
zoek = xl.worksheets("zoekenvervang").Cells(i, 1).Text
vervang = xl.worksheets("zoekenvervang").Cells(i, 2)
Call zoekenvervang(zoek, vervang)
i = i + 1
Loop Until activeworkbook.worksheets("zoekenvervang").Cells(i, 1) <> ""
xl.Workbooks.Close
Set xl = Nothing
End Sub
Thanks for your help!
IkEcht
I'm trying to do a lot of find and replace operations in word, using word vba. Getting the text to find from an excel file, as well as the replacing text.
It is in the replacing text that I have a problem. I want to be able to use code in there. So for instance replace the text Yearnow by Year(date). All of this works fine when done from within word only, but getting the data from within excel makes it malfunction. For instance in the code below even though the word "gemeente" is taken from excel, this is not replaced by "test" . Any ideas on how to solve this?
Sub vervangmaarvanuitexcel()
Dim zoek As String
Dim vervang As String
Dim vervang2 As Variant
Dim i As Integer
Dim wb As Excel.Workbook
gemeente = "test"
Set xl = CreateObject("Excel.Application")
xl.Workbooks.Open "Q:\635 Netwerkanalyse\1 - Projectdocumenten\rapportage\dummyzoekenvervang.xlsx"
i = 2
Do
zoek = xl.worksheets("zoekenvervang").Cells(i, 1).Text
vervang = xl.worksheets("zoekenvervang").Cells(i, 2)
Call zoekenvervang(zoek, vervang)
i = i + 1
Loop Until activeworkbook.worksheets("zoekenvervang").Cells(i, 1) <> ""
xl.Workbooks.Close
Set xl = Nothing
End Sub
Thanks for your help!
IkEcht