oleppedersen
New Member
- Joined
- Mar 23, 2013
- Messages
- 13
Hi all,
have searched a lot to find a solution, hope some can verify what my problem is and how to solve it.
I want to search/replace text in a Word doc from Excel. This should be plain sailing, multiple solutions exist online.
However, I can only find the text, and fill the replace dialogue box - it does not do the actual replacing.
After searching, it seems the problem is that I need to add Microsoft Word 16.0 Object Library in my reference section in my VBA. However - here I run into a message saying that the name is in conflict with "existing module, project or object library".
The libraries I have activated are: VBA for Appliations, Excel 16.0 Object Library (these two I am not allowed to switch off), Office 16.0 Object Library and OLE Automation. Switching off the latter two does not help; the error message still exists.
It seems either:
1. The reference does not matter and I have messed up the code.
2. The reference is needed, in which case I do not understand how to proceed? I use Win/Office 365 with a continuously updated Office pack.
I suspect the problem is 2), which is why I ask for help here.
Below is code for reference:
Sub DocSearch()
Dim wdApp As Object, wdDoc As Object
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open("C:\Users\OPP PC 2016\Dropbox\jobb\Visual Basic\wordtest.docx")
With wdDoc.Content.Find
.Text = "Date:"
.Replacement.Text = "Datetest"
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Set wdApp = Nothing: Set wdDoc = Nothing
End Sub
have searched a lot to find a solution, hope some can verify what my problem is and how to solve it.
I want to search/replace text in a Word doc from Excel. This should be plain sailing, multiple solutions exist online.
However, I can only find the text, and fill the replace dialogue box - it does not do the actual replacing.
After searching, it seems the problem is that I need to add Microsoft Word 16.0 Object Library in my reference section in my VBA. However - here I run into a message saying that the name is in conflict with "existing module, project or object library".
The libraries I have activated are: VBA for Appliations, Excel 16.0 Object Library (these two I am not allowed to switch off), Office 16.0 Object Library and OLE Automation. Switching off the latter two does not help; the error message still exists.
It seems either:
1. The reference does not matter and I have messed up the code.
2. The reference is needed, in which case I do not understand how to proceed? I use Win/Office 365 with a continuously updated Office pack.
I suspect the problem is 2), which is why I ask for help here.
Below is code for reference:
Sub DocSearch()
Dim wdApp As Object, wdDoc As Object
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open("C:\Users\OPP PC 2016\Dropbox\jobb\Visual Basic\wordtest.docx")
With wdDoc.Content.Find
.Text = "Date:"
.Replacement.Text = "Datetest"
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Set wdApp = Nothing: Set wdDoc = Nothing
End Sub