Can I sneak attack in melee range with a ranged weapon by flanking with another weapon

flankingpathfinder-1eranged-attackroguesneak-attack

If a rogue can catch an opponent when he is unable to defend himself effectively from her attack, she can strike a vital spot for extra damage.
The rogue’s attack deals extra damage anytime her target would be denied a Dexterity bonus to AC (whether the target actually has a Dexterity bonus or not), or when the rogue flanks her target.

So, any attack where the target has no Dex bonus to AC or the rogue is flanking, gains the Sneak Attack bonus. What is flanking?

When making a melee attack, you get a +2 flanking bonus if your opponent is threatened by another enemy character or creature on its opposite border or opposite corner.
When in doubt about whether two characters flank an opponent in the middle, trace an imaginary line between the two attackers’ centers. If the line passes through opposite borders of the opponent’s space (including corners of those borders), then the opponent is flanked.

So… only melee attacks get a flanking bonus, but clearly there's a concept of two characters flanking. Flanking Foil says

…that opponent does not gain any flanking bonus on attack rolls while it is flanking you…

So it's possible to flank without having a flanking bonus – for instance, someone affected by Flanking Foil could still use feats that required flanking. If I am flanking, with a melee weapon in the other hand or Improved Unarmed Strike to give me a threatened area, can I sneak attack with a shortbow?

Best Answer

Maybe, but it's a little complicated and not typical.

tl;dr: Sneak attack by flanking with a bow is possible with Improved Unarmed Strike, a natural attack that doesn't rely on the hands used by the bow, or another weapon wielded in a 3rd hand.

Show your work.

Enflading Fire either presumes or demonstrates that "flanked" is a persistent status (as, by extension, is "flanking"): "You receive a +2 bonus on ranged attacks made against a foe flanked by 1 or more allies with this feat". (@phoenices made an excellent point that broke a previous version of this answer using Enflading Fire, hence this paragraph's inclusion.)

To determine flanking:

... trace an imaginary line between the two attackers’ centers. If the line passes through opposite borders of the opponent’s space (including corners of those borders), then the opponent is flanked.

[or the center of any square of a large-or-larger creature]

Only a creature or character that threatens the defender can help an attacker get a flanking bonus.

Threatening's base definition is:

You threaten all squares into which you can make a melee attack, even when it is not your turn. Generally, that means everything in all squares adjacent to your space (including diagonally). ... If you’re unarmed, you don’t normally threaten any squares...

Per the shortbow description: "You need two hands to use a bow, regardless of its size." Thus, while using a bow, you can't also have a sword in your hand if you only have two hands. Therefore, while using a bow, a two-handed creature can't be flanking a foe as a result of having a melee weapon because they don't have a hand for it to be in. And, therefore, they're not actually flanking while they're using their bow.

Unarmed Strike and Natural Attacks

Unarmed Attacks can be made with "punches, kicks, and head butts" (at a minimum). Improved Unarmed Strike (per the unarmed attacks description) turns unarmed attacks into "Armed" Unarmed Attacks:

“Armed” Unarmed Attacks: Sometimes a character’s or creature’s unarmed attack counts as an armed attack. A monk, a character with the Improved Unarmed Strike feat, a spellcaster delivering a touch attack spell, and a creature with natural physical weapons all count as being armed (see natural attacks).

Note that being armed counts for both offense and defense (the character can make attacks of opportunity).

The combat rules on Natural Attacks call out that creatures "can make attacks with natural weapons in combination with attacks made with a melee weapon and unarmed strikes, so long as a different limb is used for each attack. For example, you cannot make a claw attack and also use that hand to make attacks with a longsword".

All of that together seems to mean that creatures with Improved Unarmed Strike, natural weapons that don't rely on the hands using a bow, or a 3rd hand to hold a sword still threaten squares as usual while using a bow.

So, sneak attack?

Rogues get sneak attack "when the rogue flanks her target". If the rogue has Improved Unarmed Strike, a natural weapon that doesn't depend on the hands used for the bow, and/or a third hand to hold a dagger, then they could fire into melee (with all of the normal consequences) and get sneak attack for shooting a foe that they're flanking.

Note that ranged attacks "can count as sneak attacks only if the target is within 30 feet.", so a theoretical rogue with a 35-foot reach might be able to flank a foe and sneak-attack with a dagger but not a bow.