Referencing Cells For PrToFileName (.PrintOut)

boyko

New Member
Joined
Sep 12, 2023
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am trying to reference a cell containing text information in cell "D5" on sheet "Company Lists" as apart of the PrToFileName parameter fir .PrintOut. The code works when manually replacing the "name" variable with the text inside quotation marks (ex. "AAPL").

Please see my code below:

VBA Code:
Sub Macro2()
'
' Macro2 Macro
'


'

Dim filelocation As String
Dim name As String
Dim filename As String
Dim filetype As String
Dim file As String

Sheets("Company List").Range("D3") = 1
While Sheets("Company List").Range("D3") < 41299
    
    filelocation = "G:\My Drive\BOYKO WEALTH\Boyko Data\"
    name = Sheets("Company List").Range("D5").Value
    filename = CStr(name)
    filetype = "-Boyko-Data.pdf"
    file = filelocation & filename & filetype
    
    Sheets("Company List").Select
    ActiveSheet.Range("D5").Copy
    Sheets("ENTER").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("C2").Select
    Sheets("Data Reports").Select
    Application.Wait (Now + TimeValue("0:00:05"))
    ActiveSheet.PrintOut Copies:=1, collate:=True, Preview:=False, PrintToFile:=True, PrToFileName:=file
    Sheets("Company List").Range("D3") = Sheets("Company List").Range("D3") + 1
Wend


    

    
End Sub

Thank you in advance for any help.
 
Code:
Sub What_Did_I_Forget_Question_Mark()
Dim i As Long
For i = 1 To 3    '<---- Change later to 41299
    Sheets("Company List").Range("D3") = i
        Sheets("ENTER").Range("C2").Value = Sheets("Company List").Range("D5").Value
    Sheets("Data Reports").ExportAsFixedFormat 0, "G:\My Drive\BOYKO WEALTH\Boyko Data\" & CStr(Sheets("Company List").Range("D5").Value) & ".pdf"
Next i
End Sub
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
For those wondering, I made an error in naming the file with invalid characters. Check that first if you have a problem!
 
Upvote 0
Solution

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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