fFlags = afFlags Or PD_PAGENUMS
    ElseIf PrintRange = eprSelection Then
        afFlags = afFlags Or PD_SELECTION
    End If
    ' Mask out unwanted bits
    afFlags = afFlags And Not PD_ENABLEPRINTHOOK
    afFlags = afFlags And Not PD_ENABLEPRINTTEMPLATE
    afFlags = afFlags And Not PD_ENABLESETUPHOOK
    afFlags = afFlags And Not PD_ENABLESETUPTEMPLATE
        
    ' Fill in PRINTDLG structure
    Dim pd As TPRINTDLG
    pd.lStructSize = Len(pd)
    pd.hWndOwner = Owner
    pd.flags = afFlags
    pd.nF