The formula is missing a range reference or a defined name?

John.McLaughlin

Board Regular
Joined
Jul 19, 2011
Messages
169
Hello!

I am trying to Set a print range from the relative position.

The Debug Error Highlights - ".PrintArea = FN"

Code:
Sub PDF_Relative_Position_v1()

    Application.ScreenUpdating = False

Sheets("TOOLS & SUPPLIES").Select

Dim FN As Range
Set FN = Range(ActiveCell.Offset(0, 43), ActiveCell.Offset(0, 2))
   
   
        With ActiveSheet.PageSetup
            .PrintArea = FN
        End With

    ActiveSheet.ExportAsFixedFormat _
                Type:=xlTypePDF, _
                Filename:=Range("A3"), _
                Quality:=xlQualityStandard, IncludeDocProperties:=True, _
                IgnorePrintAreas:=False, OpenAfterPublish:=True

    Application.ScreenUpdating = True


End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
That did the trick! Thank you!

I tried to use a relative cell (Column Title) for the file name, both returned errors.

Code:
FJ = Range(ActiveCell.Offset(0, 0)).Value ' filename from cell value - cursor position
FJ = Cells(ActiveCell.Offset(0, 0)).Value ' filename from cell value - cursor position


Code:
Sub PDF_Relative_Position_v1()

    Application.ScreenUpdating = False

Sheets("TOOLS & SUPPLIES").Select

Dim FN As Range
Set FN = Range(ActiveCell.Offset(0, 2), ActiveCell.Offset(43, 2))
    
FJ = Range(ActiveCell.Offset(0, 0)).Value ' filename from cell value - cursor position
    
    
    
        With ActiveSheet.PageSetup
            .PrintArea = FN.Address
        End With

    ActiveSheet.ExportAsFixedFormat _
                Type:=xlTypePDF, _
                Filename:=Range("FJ"), _
                Quality:=xlQualityStandard, IncludeDocProperties:=True, _
                IgnorePrintAreas:=False, OpenAfterPublish:=True

    Application.ScreenUpdating = True


End Sub
 
Upvote 0
Sorry, I forgot to set the Dim, but still returned the Range of object failed. Is there a suffix/syntax I missed on the Filename:=Range("FJ")?

The debug error highlights

Code:

FJ = Range(ActiveCell.Offset(0, 0)).Value ' filename from cell value - cursor position


Code:
Sub PDF_Relative_Position_v1()

    Application.ScreenUpdating = False

Sheets("TOOLS & SUPPLIES").Select

Dim FN As Range
Set FN = Range(ActiveCell.Offset(0, 2), ActiveCell.Offset(43, 2))

Dim FJ As Range

FJ = Range(ActiveCell.Offset(0, 0)).Value ' filename from cell value - cursor position
    
    
    
        With ActiveSheet.PageSetup
            .PrintArea = FN.Address
        End With

    ActiveSheet.ExportAsFixedFormat _
                Type:=xlTypePDF, _
                Filename:=Range("FJ"), _
                Quality:=xlQualityStandard, IncludeDocProperties:=True, _
                IgnorePrintAreas:=False, OpenAfterPublish:=True

    Application.ScreenUpdating = True


End Sub
 
Upvote 0
You can just use
VBA Code:
Filename:=ActiveCell.value
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,562
Messages
6,114,326
Members
448,564
Latest member
ED38

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