SOLVED
Home

Setting IF function to speak a sentence

%3CLINGO-SUB%20id%3D%22lingo-sub-837665%22%20slang%3D%22en-US%22%3ESetting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-837665%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20everyone.%20I%20am%20trying%2C%20with%20no%20success%2C%20set%20an%20IF%20command%2C%20through%20VBA%2C%20to%20speak%20a%20pre%20set%20sentence%20if%20a%20pre%20defined%20condition%20is%20reached.%3C%2FP%3E%3CP%3EExample%3A%3CU%3E%3CSTRONG%3E%3CEM%3E%3DI%3C%2FEM%3E%3CEM%3EF(%22A1%26gt%3B100%22%3B%3C%2FEM%3E%3CEM%3E%22Congratulation!!%20You%20reached%20your%20goal!%22%3B%22%22)%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FU%3E%3C%2FP%3E%3CP%3EThe%20only%20thing%20I%20know%20I%20must%20use%20%22application.speech.speak%22%20as%20one%20of%20the%20commands%20in%20this%20VBA%20macro%20but%20I%20do%20not%20know%20how%20to%20build%20this%20program.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-837665%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-837783%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-837783%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403643%22%20target%3D%22_blank%22%3E%40mctribeiro%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoes%20A1%20contain%20any%20formula%20which%20gets%20calculated%20based%20on%20other%20cells%3F%3C%2FP%3E%3CP%3EIf%20yes%2C%20you%20can%20use%20the%20Calculate%20Event%20to%20speak%20the%20predefined%20text.%20To%20do%20so%2C%20right%20click%20on%20Sheet%20Tab%20--%26gt%3B%20View%20code%20--%26gt%3B%20and%20paste%20the%20code%20given%20below%20into%20the%20opened%20code%20window.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EPrivate%20Sub%20Worksheet_Calculate()%0AIf%20Range(%22A1%22).Value%20%26gt%3B%20100%20Then%0A%20%20%20%20Application.Speech.Speak%20%22Congratulation!!%20You%20reached%20your%20goal!%22%0AEnd%20If%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20manually%20change%20the%20cell%20A1%2C%20replace%20the%20above%20code%20with%20the%20Change%20Event%20code...%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%0AIf%20Target.CountLarge%20%26gt%3B%201%20Then%20Exit%20Sub%0AIf%20Target.Address(0%2C%200)%20%3D%20%22A1%22%20Then%0A%20%20%20%20If%20Target%20%26gt%3B%20100%20Then%0A%20%20%20%20%20%20%20%20Application.Speech.Speak%20%22Congratulation!!%20You%20reached%20your%20goal!%22%2C%20True%0A%20%20%20%20End%20If%0AEnd%20If%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EThe%20attached%20contains%20two%20sheets%20named%20%22Calculate%20Event%22%20and%20%22Change%20Event%22%20for%20you%20test%20the%20above%20codes.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20this%20is%20not%20what%20you%20are%20trying%20to%20achieve%2C%20please%20upload%20a%20sample%20workbook%20and%20explain%20that%20how%20do%20you%20want%20it%20to%20work.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-837890%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-837890%22%20slang%3D%22en-US%22%3EHello%20my%20friend.%3CBR%20%2F%3EThanks%20a%20lot%20for%20your%20quick%20response.%20The%20A1%20cell%20is%20a%20result%20of%20other%20cells%20caculation%2C%20as%20your%20first%20assumption.%20I%20will%20test%20your%20command%20through%20your%20sheet%20example%20tomorrow%20and%20let%20you%20know%20the%20result.%20Thank%20you%20very%20much%20one%20more%20time.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-837895%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-837895%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403643%22%20target%3D%22_blank%22%3E%40mctribeiro%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENo%20problem%2C%20please%20test%20it%20as%20per%20your%20convenience%20and%20let%20me%20know%20if%20that%20works%20for%20you%20as%20desired.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-837933%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-837933%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403643%22%20target%3D%22_blank%22%3E%40mctribeiro%3C%2FA%3E%26nbsp%3BYou%20asked%20the%20same%20question%20on%20another%20forum%20and%20I%20answered%20it%20there.%20Please%20don't%20ask%20the%20same%20thing%20in%20different%20places.%20You%20are%20wasting%20people's%20time.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDid%20you%20try%20my%20suggestion%20in%20the%20other%20forum%3F%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fstackoverflow.com%2Fquestions%2F57779266%2Fhow-to-create-a-if-command-via-vba-to-sound-a-sentence%2F57779456%2357779456%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F57779266%2Fhow-to-create-a-if-command-via-vba-to-sound-a-sentence%2F57779456%2357779456%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20never%20replied.%20If%20people%20take%20the%20time%20to%20solve%20your%20problems%2C%20it%20would%20be%20great%20to%20give%20them%20some%20feedback.%20Happy%20to%20help%20if%20you%20need%20more%20assistance%2C%20but%20you%20have%20to%20communicate.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-837963%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-837963%22%20slang%3D%22en-US%22%3EHello.%3CBR%20%2F%3EPlease%2C%20try%20to%20not%20be%20so%20rude%20in%20your%20comments.%20If%20you%20believe%20I%20am%20wasting%20your%20time%20simply%20ignore%20my%20question.%20It%20is%20very%20easy%20to%20judge%20people's%20actions%20and%20choices.%20And%20also%20remember%3A%20don't%20judge%20to%20avoid%20being%20judged.%20I%20hope%20you%20be%20well.%20Regards.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-837964%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-837964%22%20slang%3D%22en-US%22%3EYou%20are%20a%20very%20nice%20person.%20Thank%20you%20so%20much.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-837966%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-837966%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403643%22%20target%3D%22_blank%22%3E%40mctribeiro%3C%2FA%3E%26nbsp%3BSorry%2C%20but%20I%20didn't%20mean%20to%20be%20rude%20and%20I%20don't%20think%20I%20was.%20If%20you%20post%20the%20same%20question%20in%20different%20forums%2C%20somebody%20will%20work%20on%20your%20problem%20while%20someone%20else%20has%20already%20solved%20it.%20So%20that%20is%20indeed%20wasting%20people's%20time.%26nbsp%3B%20Maybe%20you%20want%20to%20read%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.excelguru.ca%2Fcontent.php%3F184%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.excelguru.ca%2Fcontent.php%3F184%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%20explains%20things%20better%20that%20I%20did.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-837974%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-837974%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403643%22%20target%3D%22_blank%22%3E%40mctribeiro%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou're%20welcome!%20Glad%20it%20worked%20as%20desired.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-838465%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-838465%22%20slang%3D%22en-US%22%3EDear%20friend%2C%3CBR%20%2F%3EBe%20sure%20that%2C%20as%20soon%20as%20I%20solve%20this%20problem%20I%20will%20let%20people%20from%20both%20forum%20know.%20So%20far%2C%20nobody%20got%20the%20solution.%20And%20if%20you%20check%2C%20I%20posted%20my%20situatuon%20at%20the%20same%20time%2C%20considering%20that%20I%20will%20reach%20different%20people%20in%20two%20different%20forums%2C%20increasing%20the%20chance%20for%20a%20quick%20answer.%20Anyway%2C%20try%20to%20be%20more%20polite%20next%20time%20you%20take%20your%20precious%20time%20to%20help%20other%20people%20otherwise%20is%20better%20if%20you%20do%20something%20else.%20Please%2C%20do%20not%20take%20it%20as%20offense%20but%20as%20a%20suggestion%20from%20someone%20probably%20older%20than%20you.%20Regards.%3CBR%20%2F%3ERegards%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-838466%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-838466%22%20slang%3D%22en-US%22%3EBy%20the%20way%2C%20I%20read%20the%20article%20from%20that%20link.%20I%20completely%20understand%20your%20point%20and%20will%20follow%20some%20given%20tips.%20Thank%20you.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-838888%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-838888%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3EHi%20my%20friend.%20I%20tested%20your%20program%20this%20morning%20and%20it%20worked%20almost%20perfectly.%20The%20only%20problem%20was%20the%20voice%20started%20a%20loop%20and%20did%20not%20stop%20at%20all.%20I%20had%20to%20shut%20Excell%20(not%20only%20the%20specific%20sheet)%20to%20definitely%20quit%20the%20voice.%20I%20am%20attaching%20the%20sheet%20which%20will%20receive%20the%20voice%20command.%20I%20highlighted%20in%20yellow%20the%20column%20with%20the%20cells%20that%20will%20%22produce%22%20the%20voice.%20Please%2C%20let%20me%20know%20if%20I%20did%20something%20wrong.%20My%20best%20regards%2C%3C%2FP%3E%3CP%3EMarcelo%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-839089%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-839089%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3Ehere%20I%20come%20again.%20I%20found%20out%20when%20the%20loop%20happens.%20The%20original%20sheet%2C%20with%20some%20cells%20which%20numbers%20come%20from%20another%20program%26nbsp%3Bvia%20DDE%2C%20Dinamic%20Data%20Exchange%2C%20in%20real%20time%20the%20voice%20starts%20an%20endless%20loop%20when%20the%20condition%20is%20reached%20but%20in%20the%20sheet%20I%20sent%20you%2C%20with%20frozen%20cells%2C%20your%20program%20works%20perfectly%20(exception%3A%20if%20one%20the%20cells%20used%20in%20the%20formula%20turns%20to%20something%20else%20but%20a%20number%20the%20VBA%20bugs).%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-839289%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-839289%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403643%22%20target%3D%22_blank%22%3E%40mctribeiro%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20code%20I%20proposed%20was%20supposed%20to%20work%20for%20a%20single%20cell%20A1.%3C%2FP%3E%3CP%3EIn%20your%20sample%20file%2C%20are%20you%20looping%20through%20the%20column%20U%20and%20want%20the%20code%20to%20check%20the%20formula%20output%20for%20multiple%20cells%20in%20column%20U%20and%20then%20speak%20the%20text%20once%20a%20specific%20output%20is%20returned%20by%20the%20formula%20in%20one%20or%20more%20cells%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESince%20this%20is%20the%20Calculate%20event%2C%20each%20time%20Sheet%20is%20recalculated%20the%20code%20will%20be%20triggered%20and%20check%20the%20target%20cell%2Fcells%20for%20the%20output%20returned%20by%20the%20formula%20and%20if%20that%20meets%20the%20criteria%2C%20the%20code%20will%20invoke%20the%20speech%20method%20and%20to%20handle%20this%20scenario%2C%20you%20can%20place%20a%20flag%20once%20the%20text%20is%20spoken%20for%20a%20cell%20either%20by%20using%20a%20helper%20column%20and%20placing%20a%20flag%20in%20there%20or%20you%20can%20change%20the%20cell%20color%20so%20that%20the%20code%20can%20check%20before%20speaking%20the%20text%20if%20the%20cell%20color%20is%20not%20a%20specific%20color%20i.e.%20once%20the%20code%20speaks%20the%20text%20for%20a%20cell%2C%20change%20the%20cell%20color%20to%20say%20Red%20and%20the%20next%20time%20code%20will%20check%20the%20cell%20color%20and%20if%20it%20is%20red%2C%20it%20will%20skip%20and%20won't%20speak%20the%20text%20for%20the%20same%20cell%20again.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20far%20as%20the%20VBA%20errors%20are%20concerned%20when%20the%20value%20is%20not%20numeric%2C%20I%20think%20the%20code%20will%20produce%20an%20error%20if%20the%20cell%20has%20an%20error%20in%20it%20which%20you%20can%20easily%20check%20in%20the%20code%20with%20an%20IF%20condition%20like%20%3CSTRONG%3EIf%20Not%20IsError(Range(%22A1%22))%20Then%3C%2FSTRONG%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-839506%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-839506%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3Emy%20idea%20is%20to%20write%20an%20specific%20sentence%20for%20each%20cell%20in%20column%20%22U%22%20as%20each%20line%20refers%20to%20a%20different%20information.%20How%20can%20write%20a%20formula%20that%20consider%20it%20or%20is%20it%20to%20complicate%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-839587%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-839587%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403643%22%20target%3D%22_blank%22%3E%40mctribeiro%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHonestly%2C%20in%20my%20opinion%2C%20forcing%20the%20macro%20to%20speak%20out%20several%20sentences%20in%20one%20go%20would%20be%20like%20overuse%20of%20this%20feature.%20Why%20not%20add%20some%20visuals%20on%20the%20sheet%20once%20one%20or%20more%20criteria%20are%20met%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-839682%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-839682%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EActually%20I%20thought%20it%20as%20well%20but%20a%20%22voice%20alert%22%20would%20work%20better.%20However%20I%20undertand%20your%20point.%20There%20is%20another%20solution%20do%20make%20the%20macro's%20work%20lighter%3A%20split%20my%20worksheet%20in%20several%20different%20sheets%2C%20each%20one%20with%20its%20own%20macro.%20Well%2C%20I%20do%20not%20know.%20Let%20me%20see%20how%20hard%20it%20would%20be%20to%20decide%20which%20way%20I%20will%20take.%20Anyway%2C%20I%20don't%20want%20to%20push%20you%20with%20this%20demand.%20Thanks%20a%20lot%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3Bfor%20your%20valuable%20help.%20I%20will%20keep%20trying.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-842519%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-842519%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E.%20As%20I%20am%20new%20in%20this%20forum%20how%20do%20I%20mark%20in%20my%20post%20it%20has%20been%20solved%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-842648%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20IF%20function%20to%20speak%20a%20sentence%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-842648%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403643%22%20target%3D%22_blank%22%3E%40mctribeiro%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYour%20question%20gets%20marked%20as%20Solved%20once%20you%20confirm%20any%20post%20as%20a%20Best%20Response%20and%20you%20have%20already%20done%20that%20though%20you%20chose%20the%20wrong%20one%20as%20Best%20Response%20as%20that%20post%20didn't%20contain%20any%20solution.%3C%2FP%3E%3CP%3EIf%20a%20post%20is%20helpful%20you%20can%20hit%20the%20Like%20button%20for%20that%20post%20but%20the%20post%20which%20resolved%20your%20question%20by%20offering%20a%20solution%20should%20be%20confirmed%20as%20the%20Best%20Response.%3C%2FP%3E%3CP%3EOnce%20a%20question%20is%20marked%20as%20Solved%2C%20you%20will%20observe%20a%20green%20triangle%20with%20a%20while%20tick%20mark%20like%20below...%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20773px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F130607i6324BDAF938A1D8D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Solved.jpg%22%20title%3D%22Solved.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBtw%2C%20I%20am%20also%20new%20to%20this%20forum.%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
mctribeiro
Occasional Contributor

 

Hi everyone. I am trying, with no success, set an IF command, through VBA, to speak a pre set sentence if a pre defined condition is reached.

Example: =IF("A1>100";"Congratulation!! You reached your goal!";"")

The only thing I know I must use "application.speech.speak" as one of the commands in this VBA macro but I do not know how to build this program.

 

18 Replies

@mctribeiro 

Does A1 contain any formula which gets calculated based on other cells?

If yes, you can use the Calculate Event to speak the predefined text. To do so, right click on Sheet Tab --> View code --> and paste the code given below into the opened code window.

 

Private Sub Worksheet_Calculate()
If Range("A1").Value > 100 Then
    Application.Speech.Speak "Congratulation!! You reached your goal!"
End If
End Sub

 

If you manually change the cell A1, replace the above code with the Change Event code...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Target.Address(0, 0) = "A1" Then
    If Target > 100 Then
        Application.Speech.Speak "Congratulation!! You reached your goal!", True
    End If
End If
End Sub

The attached contains two sheets named "Calculate Event" and "Change Event" for you test the above codes.

 

If this is not what you are trying to achieve, please upload a sample workbook and explain that how do you want it to work.

 

 

Hello my friend.
Thanks a lot for your quick response. The A1 cell is a result of other cells caculation, as your first assumption. I will test your command through your sheet example tomorrow and let you know the result. Thank you very much one more time.
Solution

@mctribeiro 

No problem, please test it as per your convenience and let me know if that works for you as desired.

@mctribeiro You asked the same question on another forum and I answered it there. Please don't ask the same thing in different places. You are wasting people's time. 

 

Did you try my suggestion in the other forum? https://stackoverflow.com/questions/57779266/how-to-create-a-if-command-via-vba-to-sound-a-sentence/...

 

You never replied. If people take the time to solve your problems, it would be great to give them some feedback. Happy to help if you need more assistance, but you have to communicate.

 

Hello.
Please, try to not be so rude in your comments. If you believe I am wasting your time simply ignore my question. It is very easy to judge people's actions and choices. And also remember: don't judge to avoid being judged. I hope you be well. Regards.
You are a very nice person. Thank you so much.

@mctribeiro Sorry, but I didn't mean to be rude and I don't think I was. If you post the same question in different forums, somebody will work on your problem while someone else has already solved it. So that is indeed wasting people's time.  Maybe you want to read this:

 

https://www.excelguru.ca/content.php?184

 

It explains things better that I did. 

@mctribeiro 

You're welcome! Glad it worked as desired.

 

Dear friend,
Be sure that, as soon as I solve this problem I will let people from both forum know. So far, nobody got the solution. And if you check, I posted my situatuon at the same time, considering that I will reach different people in two different forums, increasing the chance for a quick answer. Anyway, try to be more polite next time you take your precious time to help other people otherwise is better if you do something else. Please, do not take it as offense but as a suggestion from someone probably older than you. Regards.
Regards
By the way, I read the article from that link. I completely understand your point and will follow some given tips. Thank you.

@Subodh_Tiwari_sktneerHi my friend. I tested your program this morning and it worked almost perfectly. The only problem was the voice started a loop and did not stop at all. I had to shut Excell (not only the specific sheet) to definitely quit the voice. I am attaching the sheet which will receive the voice command. I highlighted in yellow the column with the cells that will "produce" the voice. Please, let me know if I did something wrong. My best regards,

Marcelo

@Subodh_Tiwari_sktneerhere I come again. I found out when the loop happens. The original sheet, with some cells which numbers come from another program via DDE, Dinamic Data Exchange, in real time the voice starts an endless loop when the condition is reached but in the sheet I sent you, with frozen cells, your program works perfectly (exception: if one the cells used in the formula turns to something else but a number the VBA bugs).

@mctribeiro 

The code I proposed was supposed to work for a single cell A1.

In your sample file, are you looping through the column U and want the code to check the formula output for multiple cells in column U and then speak the text once a specific output is returned by the formula in one or more cells?

 

Since this is the Calculate event, each time Sheet is recalculated the code will be triggered and check the target cell/cells for the output returned by the formula and if that meets the criteria, the code will invoke the speech method and to handle this scenario, you can place a flag once the text is spoken for a cell either by using a helper column and placing a flag in there or you can change the cell color so that the code can check before speaking the text if the cell color is not a specific color i.e. once the code speaks the text for a cell, change the cell color to say Red and the next time code will check the cell color and if it is red, it will skip and won't speak the text for the same cell again.

 

As far as the VBA errors are concerned when the value is not numeric, I think the code will produce an error if the cell has an error in it which you can easily check in the code with an IF condition like If Not IsError(Range("A1")) Then.

@Subodh_Tiwari_sktneermy idea is to write an specific sentence for each cell in column "U" as each line refers to a different information. How can write a formula that consider it or is it to complicate?

@mctribeiro 

Honestly, in my opinion, forcing the macro to speak out several sentences in one go would be like overuse of this feature. Why not add some visuals on the sheet once one or more criteria are met?

@Subodh_Tiwari_sktneer 

Actually I thought it as well but a "voice alert" would work better. However I undertand your point. There is another solution do make the macro's work lighter: split my worksheet in several different sheets, each one with its own macro. Well, I do not know. Let me see how hard it would be to decide which way I will take. Anyway, I don't want to push you with this demand. Thanks a lot @Subodh_Tiwari_sktneer for your valuable help. I will keep trying.

Hi @Subodh_Tiwari_sktneer . As I am new in this forum how do I mark in my post it has been solved?

@mctribeiro 

Your question gets marked as Solved once you confirm any post as a Best Response and you have already done that though you chose the wrong one as Best Response as that post didn't contain any solution.

If a post is helpful you can hit the Like button for that post but the post which resolved your question by offering a solution should be confirmed as the Best Response.

Once a question is marked as Solved, you will observe a green triangle with a while tick mark like below...

Solved.jpg

 

Btw, I am also new to this forum.

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
35 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies