Avatar of jmacalpine
jmacalpine
 asked on

VBA Error

I have a VBA script to run.. Get an error 5 When I try to run..Upon debugging, I am told that the Line (I've underlined it) below is using the wrong argument... I've tried a few different ways to declare that worksheet as the one I need but to no avail.

Thoughts?


Sub Tally()
Dim subj As String
subj = Worksheets("Bol Breakdown").Range("R1").Value
company = Worksheets("New").Range("N1").Value
filesformat = "PDF\Tally Sheets"
livescrap = Worksheets("New").Range("N3").Value
yeardate = Worksheets("New").Range("N4").Value
monthdate = Worksheets("New").Range("N5").Value
pathtosaveto = "S:\ARC\" & company & "\" & filesformat & "\" & yeardate & "\" & monthdate & "\" & subj

Worksheets("BOL Breakdown").ExportAsFixedFormat Type:=xlTypePDF, Filename:=pathtosaveto, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
VB ScriptVBA

Avatar of undefined
Last Comment
Surone1

8/22/2022 - Mon
Martin Liss

Well I don't know what is in your "pathtosaveto" but otherwise your code works for me. If the sheet name were incorrect you'd get a Subscript out of range error.
jmacalpine

ASKER
pathtosaveto = "S:\ARC\" & company & "\" & filesformat & "\" & yeardate & "\" & monthdate & "\" & subj
ASKER CERTIFIED SOLUTION
Martin Liss

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Surone1

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61