VBA problem calling MS Word

matttclark

Board Regular
Joined
Jan 13, 2011
Messages
100
Hi I am having a problem that is driving me nuts. I have not worked a lot with binding to other apps but I have searched and searched and tried different suggestions/variants to no avail, would GREATLY appreciate any help.

I tested the following code natively (without the added binding) in MS Word and it works fine, however when I try to call it from Excel, I can not get it to work. It executes, a new Word fiel is opened, the data is pasted in and I get no errors, but it does not replace anything in MS Word.

What am I doing wrong?? Using Office 2007

Thanks much! (very , very much)

Code:
Sub minitest3()

Dim appWD As Object    'Word.Application

' Create a new instance of Word & make it visible
Set appWD = CreateObject("Word.Application")
appWD.Visible = True

'add new doc, paste data from clipboard
appWD.documents.Add
appWD.Selection.Paste

'NO ERRORS BUT NOTHING GETS REPLACED
Set myRange = appWD.ActiveDocument.Content
myRange.Find.Execute FindText:="^lGrade: ", _
    ReplaceWith:="^t", Replace:=wdReplaceAll
    
Set appWD = Nothing

MsgBox "done"
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
You might need to replace the Word VBA constant wdReplaceAll with the actual value.

You'll find that in the Object Browser(F2) in Word VBA.

In fact you'll find a declaration you can add to your code so you can still use wdReplaceAll.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top