Andrew,
Several comments:
The SetAttributes[foo, HoldAll]
makes foo accept Symbols that are defined in the Kernel. This might never be an issue for your code but it is generally a good idea.
Modifying your latest post to put the button in place of what the user typed you can do:
foo[symb1_] :=
Module[{symb12, obj, nb},
symb12 =
Switch[Head@symb1, Symbol, SymbolName[Unevaluated[symb1]], String,
symb1]; foo2[symb12a_String] := Button[symb12a, Speak@symb12a];
obj = EvaluationCell[];
SelectionMove[obj, All, Cell]; nb = EvaluationNotebook[];
Print[foo2@symb12]; NotebookDelete[nb];
SelectionMove[nb, Next, Cell]; SelectionMove[nb, After, Cell]];
This code uses Notebook Manipulation commands to select the current cell, print the button, delete the input that was typed by the user and move after the button so it looks like what you asked for.
Next it is a good idea to localize variables in a Module[]. You should not be creating global variables here. (symb12, obj, nb, and anything else you add)
Lastly, I Don't like using Switch[] in functions like this. Mathematica is suited to operator overloading and it makes for better code although this is a matter of programming style.
I would do:
foo[symb1_Symbol] :=
Module[{ sym = SymbolName[Unevaluated[symb1]], obj, nb},
obj = EvaluationCell[]; nb = EvaluationNotebook[];
SelectionMove[obj, All, Cell]; Print[Button[sym, Speak@sym]];
NotebookDelete[nb]; SelectionMove[nb, Next, Cell];
SelectionMove[nb, After, Cell]];
foo[symb1_String] :=
Module[{ obj, nb}, obj = EvaluationCell[]; nb = EvaluationNotebook[];
SelectionMove[obj, All, Cell]; Print[Button[symb1, Speak@symb1]];
NotebookDelete[nb]; SelectionMove[nb, Next, Cell];
SelectionMove[nb, After, Cell]];
SetAttributes[foo, HoldAll]
This code defines a foo function for Symbols and a foo function that take strings. The appropriate function is used for the appropriate input. (operator overloading).
Regards
Neil