Replace footer in word with excel macro error

hlg0035

New Member
Joined
Sep 8, 2014
Messages
13
Hello all-

I'm trying to replace the footer information in Word with this (see below) and I receive this error: compile error: user-defined type not defined. Any help would be appreciated!

'Replace the footer info
Dim oSection As Word.Section
Dim oRange As Word.Range
Dim Var
For Each oSection In WrdDoc.Sections()
Set oRange = oSection.Footers(Var).Range
oRange.Find.Execute FindText:="[CDAREPDATE]"
Set oRange = Nothing
Next
Next
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
No that doesn't set a Reference. You can't do this with late binding:

Code:
Dim oSection As Word.Section
Dim oRange As Word.Range

try declaring them as Object.
 
Upvote 0
Thank you, this is what I have now:

I am getting an error with the bolded line item now: The requested member of the collection does not exist

Dim oSection As Object
Dim oRange As Object
Dim Var
For Each oSection In WrdDoc.Sections()
Set oRange = oSection.Footers(Var).Range
oRange.Find.Execute FindText:="[CDAREPDATE]"
Set oRange = Nothing
Next


No that doesn't set a Reference. You can't do this with late binding:

Code:
Dim oSection As Word.Section
Dim oRange As Word.Range

try declaring them as Object.
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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