Problem VBA REPLACE FUNCTION

IGORR

New Member
Joined
Apr 24, 2015
Messages
6
Good morning;

I need the help o somebody with the following code.

The error is "Argument not valid".

Sub PrintPDFServ() '*****Imprimir sin visualizacion*****
Application.ScreenUpdating = False
'Para Crear archivos PDF Desde Excel nada mas tienes que instalar el complemeto para guardar archivos pdf de Oficce
Dim sDate
sName = Replace(Sheets("Ficha Tecnica Serv").Range("E6"), ".", "_")
sDescrip = Replace(Sheets("Ficha Tecnica Serv").Range("E8"), ".", "_")
Set sDate = Sheets("Ficha Tecnica Serv").Range("I6")
XName = sName & "-" & sDescrip & " (" & Format(sDate, "ddmmyyyy") & ")"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"\\SERVIDORVELL\docs\Ejea\Calidad\Especificaciones\Especificaciones Tecnicas Materiales\Papel\Fichas Tecnicas de Papel\Definitivo\" & XName & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Application.ScreenUpdating = True
End Sub

Thanks in advance.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Why two "\\" at address name? change address to simple address like "D:\" and test it.
 
Upvote 0
It is not the problem.

The code works perfectly before I introduced this two lines:

sName = Replace(Sheets("Ficha Tecnica Serv").Range("E6"), ".", "_")
sDescrip = Replace(Sheets("Ficha Tecnica Serv").Range("E8"), ".", "_")

With this two lines; I try avoid problems with the name of the pdf printed when found points.

I used "set" before this two lines, and the mistake was other "error compilation, objet required.
 
Upvote 0
I test you macro with Sheet1 name and it run without Problem.
Are your sheet name doesn't have extra space or character at excel sheet name? Check it.
 
Upvote 0
I agree with maabadi. I think your sheet name is most likely the issue.
What happens if you run this code?
VBA Code:
Sub Text()
    Sheets("Ficha Tecnica Serv").Activate
End Sub
If that doesn't work, then the only two things I can think of that would cause that would be:
- The sheet name is not really "Ficha Tecnica Serv" (you may have some extra spaces in there somewhere)
- The sheet is hidden so it cannot be selected
 
Upvote 0
The problem is when in Range("E6") and Range("E8") appears ".".

sName = Replace(Sheets("Ficha Tecnica Serv").Range("E6"), ".", "_")
sDescrip = Replace(Sheets("Ficha Tecnica Serv").Range("E8"), ".", "_")

These two lines convert "." in "_" becuase it is not possible to name the pdf with points between in the text.

Please, insert one point ins your example and sure it will give you the same error "Invalid argument".

When I use the example without points it works like your example, the problem is I need it works with points.

Thanks in advance.
 
Upvote 0
Please, insert one point ins your example and sure it will give you the same error "Invalid argument".
It does not. It works just fine for me, and runs to completion without errors.

Can you post exactly what is in cell E6 and E8?
You may have some other illegal characters in there that you cannot use in file paths or file names.
 
Upvote 0
If you are getting the compile error on this line
VBA Code:
sName = Replace(Sheets("Ficha Tecnica Serv").Range("E6"), ".", "_")
Check that you don't have any procedures or variables called Replace
 
Upvote 0
E6 = Z01020325.903
E8= TISU SERV. 2C ROSA FRAMBUESA 16,5grs 32cms ECOLABEL *FSC MIX CREDIT*
 
Upvote 0
E8= TISU SERV. 2C ROSA FRAMBUESA 16,5grs 32cms ECOLABEL *FSC MIX CREDIT*
Yep, just as I expected. You cannot use "*" in file folders names or file names.
You need to remove those too.

You can remove those like this:
VBA Code:
sDescrip = Replace(Replace(Sheets("Ficha Tecnica Serv").Range("E8"), ".", "_"), "*", "")
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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