Code working within a file, giving Error 448 within another file

zankzank

New Member
Joined
Mar 21, 2023
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Dear all, I am facing a strange problem with Excel.
I created an excel file (let's call it File A) to see if the following code was working

VBA Code:
Const wdReplaceAll = 2

Sub Test()
Dim wApp As Object

Dim wDoc As Object

Dim LastR As Long

Dim ST, RT As Variant

Dim R As Integer

Dim fiName, vers, utente As Variant

LastR = Sheets("Fields").Cells(Sheets("Fields").Rows.Count, "A").End(xlUp).Row

fiName = Sheets("Main").Cells(2, 4)

vers = Sheets("Main").Cells(3, 4)

utente = Sheets("Main").Cells(5, 4)

On Error Resume Next

Set wApp = GetObject(, "Word.Application")

If Err.Number <> 0 Then

Set wApp = CreateObject("Word.Application")

End If

On Error GoTo 0

Temp = "C:\Users\" & utente & "\Downloads\"

Set wDoc = wApp.Documents.Open("C:\Users\" & utente & "\Downloads\Specs.docx", ReadOnly = True)

If wDoc Is Nothing Then

MsgBox "Could not find the template file at:" & "C:\Users\" & utente & "\Downloads\Specs.docx"

Exit Sub

End If

On Error Resume Next

wDoc.SaveAs Temp & "\" & fiName & "_" & vers & ".docx"

On Error GoTo 0

If wDoc Is Nothing Then

MsgBox "Could not save the word file at: " & Temp & "\" & fiName & "_" & vers & ".docx"

Exit Sub

End If

For R = 27 To LastR

ST = Sheets("Fields").Cells(R, 1)

RT = Sheets("Fields").Cells(R, 2)

wDoc.Content.Find.Execute Wrap:=1, FindValue:=ST, ReplaceWith:=RT, Replace:=wdReplaceAll

didSome = wDoc.Content.Find.Found

Next R

wDoc.Save

wDoc.Close

Set wApp = Nothing

MsgBox ("The file " & fiName & "_" & vers & ".docx was successfully created in C:\Users\" & utente & "\Downloads\")

End Sub

and everything was working ok.
I then created a copy of this file, renamed it (let's call this new file as File B) and added forms, additional Sheets etc... but, to my surprise, the code was no longer working: I am now receiving "Run-time error '448': Named argument not found". The error points to the line

VBA Code:
wDoc.Content.Find.Execute Wrap:=1, FindValue:=ST, ReplaceWith:=RT, Replace:=wdReplaceAll

Could someone be so kind to explain how it is possible that the same code was working (and is still working) for FileA, but not for FileB ?
Thank you in advance for your help!
Best,
Silvano
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
FindValue should be FindText in that line. (I suspect it wasn't actually executing in your other file)
 
Upvote 1
Solution

Forum statistics

Threads
1,223,101
Messages
6,170,116
Members
452,302
Latest member
TaMere

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