Also you can return the vla-object list with foreach by wrapping it in mapcar.  eliminating having to use (setq o (vlax-ename->vla-object e)).  Pulling the vla-object name before the cond means your checking the variable rather then check the entity up to 3 times.
 
	 
 
; Original by RonJonP, edited by P. Kenewell, updated by Mhupp
(defun c:ltx (/ D O S)
  (vl-load-com)
  (setq D (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark D)
  (if (setq s (ssget ":L" '((0 . "*TEXT,DIMENSION"))))
    (foreach o (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
      (setq typ (vla-get-ObjectName o))
      (cond
        ((= typ "AcDbText")   
          (vla-put-textstring o (strcat "%%O" (vl-string-subst "" "" (vl-string-subst "" "%%O" (vla-get-textstring o)))))
        )
        ((= typ "AcDbMText")  
          ...
        )
        ((= typ "AcDbDimension")
          ...
        )
      )
    )
  )
  (vla-endundomark D)
  (princ)
)
	 
 
	-edit
 
	also useing the (vla-startundomark allows you to have things selected before you run the command.