Can any diminished chord be used as V anywhere?
In tonal harmony you can play a diminished chord on any root any time and have it act as a dominant (better to call it a dominant and not a
V, it's Roman numeral should always be
viio) to some tonic. But that statement is broad to the point of not being useful.
You asked about "anywhere?" What do you mean exactly?
This wording is too vague, we are talking about tonal harmony, we need specifics about key and chord, words that have musical meaning, not pronouns.
The matter is entire about the sense of being in a key.
Keys have tonics of either a major or minor triad, those tonics have leading tones, and a diminished chord can be built on the leading tone which has a dominant function resolving to the tonic chord. Those concepts are all bundled up when symbols like
viio are used.
You can change key or temporarily tonicize another tonic in tonal music.
A secondary leading tone chord, the
viio chord, can be applied to any diatonic chord, except the
viio chord, or
iio chord in minor, because a diminished chord cannot be a tonic in tonal harmony.
So, for example, in
C major you can have
viio itself and secondary chords
viio/V', viio/vi'. But, you cannot have
C major that would be a
Bb diminished chord claiming to resolve to a tonic of
B diminished, which is tonal nonsense.
However, you could have music in
C major, introduce a
Bb diminished chord, and it would imply a change in the tonal focus, that chord would resolve to either a
B major or
B minor tonic. It would really take you away from
This brings us back to what you mean by "anywhere?"
If you mean, can I use a diminished chord anywhere within a give key, and keep within the conventions of tonal harmony? Then, no.
You posed the question with reference to Roman numeral analysis and function. That frames the question within the conventions of tonal harmony.
If you mean, can I use a diminished chord anywhere, regardless of key or tonal conventions? Then, yes. You can use any chord any time. It just won't necessarily be conventional tonal harmony.
...in a ii-V-I progression -- I sharpen the 5th note of the scale and hang a diminished triad over it. So in C major I would use G# diminished for V...
If the purpose is to use diminished chords as dominants, it will clarify things to think of them with the common label leading tone chords, leading tone triad or leading tone diminished seventh chords.
So, this case will be less confusing if the chord were spelled as a leading tone diminished seventh chord. Not
G# B D, but
Ab B D which is just an inversion of
B D Ab, which is simply the
viio7 chord in
C major. That makes
ii V I become
ii viio I, and that functionally the same: subdominant dominant tonic. In other words, if it's functioning as a dominant the root is not
G# leading tone to
A, but root
B leading tone to
...I've just been trying Eb diminished and it sounds dominant too but I don't understand why...
The voicing might matter with this one. I played it in close voicing
Dm7/C Ebdim7/C Cadd6 (you call it an
Eb diminished so I wrote
Ebdim7/C instead of
Cdim7.) With my particular voicing you have a chromatic ascent of
E♮ G♮. Chromatic steps like that certainly have "pull" but that doesn't sound like dominant function. Dominant function is
TI FA resolving to
DO MI. So, this case is a kind of embellishing or passing chord, not a dominant. Like @Dekkadeci answer, you can all it a common tone diminished seventh chord.