Compile error: Invalid Qualifier (VBA)

troglodyte

New Member
Joined
Sep 9, 2014
Messages
11
Code:
Sub PDFCreator()
'
' PDF Creator Macro
'This should create an individual PDF for each variable and save it in the correct location
'
 
'
'Define the save location
'
 
    Dim FName As String
    Dim FPath As String
    Dim rng As Range, cell As Range
   
    FPath = "Q:\Files\
    FName = Sheets("Core Data").Range("D4").Text
 
'
'Selects the list of variables in these cells
'
 
    Set rng = Range("A2:A40")
    For Each cell In rng
    Range("A2").Select
    Selection.Copy
    Range("D2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Summary page").Select
    Application.CutCopyMode = False
 
'
'Input a timer delay here as the file is quite large and needs time to refresh for a new input
'
 
    Application.Wait (Now + TimeValue("0:00:15"))
    ThisWorkbook.SaveAs filename:=FPath & "\" & FName.pdf
 
   
   Next cell
   
End Sub

The above VBA (I hope) will cycle through a list of variables in a range (A2:A40) and for each variable in that range the code will save a PDF version of the "Summary Page" in the specified location. I'm still learning VBA and the above is throwing a Compile error at me, I'm not too sure why? I would be grateful for any pointers here!

Thank you.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi there,

ThisWorkbook.SaveAs filename:=FPath & "\" & FName.pdf

...is an Oopsie.

If the text in range D4 does not include the file extension, then you want to concatenate ".pdf"; something like: ThisWorkbook.SaveAs filename:=FPath & "\" & FName & ".pdf"

Does that get it done?

Mark
 
Upvote 0
GTO, thank you that worked! I will have to increase the delay on the macro I think but aside from that it's all working fine so thank you.
 
Upvote 0

Forum statistics

Threads
1,215,398
Messages
6,124,690
Members
449,179
Latest member
kfhw720

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