Message Box and Sound Play simultaneously - VBA





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1















In the code below, the song is played first, after which the message is displayed. How to display the Message Box and Sound Play simultaneously in the code below?



Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As LongPtr, ByVal dwFlags As Long) As Boolean

Private Sub CommandButton1_Click()
Call PlaySound("c:windowsmediatada.wav", 0, SND_ASYNC Or SND_FILENAME)
Msgbox "Process completed successfully."
End Sub









share|improve this question




















  • 1





    Did you actually declare SND_ASYNC and SND_FILENAME?

    – GSerg
    Nov 23 '18 at 15:49








  • 1





    Is Option Explicit specified? If SND_ASYNC and SND_FILENAME aren't defined, you're passing 0 Or 0 (i.e. 0) as the last parameter, which presumably isn't the right value.

    – Mathieu Guindon
    Nov 23 '18 at 15:54











  • What is your suggestion for code reform? Can you explain more?

    – stackoverflow2018
    Nov 23 '18 at 15:57











  • Those constants SND_ASYNC and SND_FILENAME are not declared. You can't just pass them like this since they will be treated as a variable and will default to 0. So you are essentially just running Call PlaySound("C:WindowsMediatada.wav, 0, 0) which is not doing what you want it to do. Check out this link at Chip Pearson's site where he has a good working example of this function with the constants declared in the code.

    – JNevill
    Nov 23 '18 at 16:11











  • Thank you @JNevill! The following line should be added to the code: Const SND_ASYNC = &H1

    – stackoverflow2018
    Nov 23 '18 at 16:20


















-1















In the code below, the song is played first, after which the message is displayed. How to display the Message Box and Sound Play simultaneously in the code below?



Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As LongPtr, ByVal dwFlags As Long) As Boolean

Private Sub CommandButton1_Click()
Call PlaySound("c:windowsmediatada.wav", 0, SND_ASYNC Or SND_FILENAME)
Msgbox "Process completed successfully."
End Sub









share|improve this question




















  • 1





    Did you actually declare SND_ASYNC and SND_FILENAME?

    – GSerg
    Nov 23 '18 at 15:49








  • 1





    Is Option Explicit specified? If SND_ASYNC and SND_FILENAME aren't defined, you're passing 0 Or 0 (i.e. 0) as the last parameter, which presumably isn't the right value.

    – Mathieu Guindon
    Nov 23 '18 at 15:54











  • What is your suggestion for code reform? Can you explain more?

    – stackoverflow2018
    Nov 23 '18 at 15:57











  • Those constants SND_ASYNC and SND_FILENAME are not declared. You can't just pass them like this since they will be treated as a variable and will default to 0. So you are essentially just running Call PlaySound("C:WindowsMediatada.wav, 0, 0) which is not doing what you want it to do. Check out this link at Chip Pearson's site where he has a good working example of this function with the constants declared in the code.

    – JNevill
    Nov 23 '18 at 16:11











  • Thank you @JNevill! The following line should be added to the code: Const SND_ASYNC = &H1

    – stackoverflow2018
    Nov 23 '18 at 16:20














-1












-1








-1








In the code below, the song is played first, after which the message is displayed. How to display the Message Box and Sound Play simultaneously in the code below?



Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As LongPtr, ByVal dwFlags As Long) As Boolean

Private Sub CommandButton1_Click()
Call PlaySound("c:windowsmediatada.wav", 0, SND_ASYNC Or SND_FILENAME)
Msgbox "Process completed successfully."
End Sub









share|improve this question
















In the code below, the song is played first, after which the message is displayed. How to display the Message Box and Sound Play simultaneously in the code below?



Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As LongPtr, ByVal dwFlags As Long) As Boolean

Private Sub CommandButton1_Click()
Call PlaySound("c:windowsmediatada.wav", 0, SND_ASYNC Or SND_FILENAME)
Msgbox "Process completed successfully."
End Sub






excel vba userform






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 17:44









GSerg

60.3k15108237




60.3k15108237










asked Nov 23 '18 at 15:37









stackoverflow2018stackoverflow2018

73




73








  • 1





    Did you actually declare SND_ASYNC and SND_FILENAME?

    – GSerg
    Nov 23 '18 at 15:49








  • 1





    Is Option Explicit specified? If SND_ASYNC and SND_FILENAME aren't defined, you're passing 0 Or 0 (i.e. 0) as the last parameter, which presumably isn't the right value.

    – Mathieu Guindon
    Nov 23 '18 at 15:54











  • What is your suggestion for code reform? Can you explain more?

    – stackoverflow2018
    Nov 23 '18 at 15:57











  • Those constants SND_ASYNC and SND_FILENAME are not declared. You can't just pass them like this since they will be treated as a variable and will default to 0. So you are essentially just running Call PlaySound("C:WindowsMediatada.wav, 0, 0) which is not doing what you want it to do. Check out this link at Chip Pearson's site where he has a good working example of this function with the constants declared in the code.

    – JNevill
    Nov 23 '18 at 16:11











  • Thank you @JNevill! The following line should be added to the code: Const SND_ASYNC = &H1

    – stackoverflow2018
    Nov 23 '18 at 16:20














  • 1





    Did you actually declare SND_ASYNC and SND_FILENAME?

    – GSerg
    Nov 23 '18 at 15:49








  • 1





    Is Option Explicit specified? If SND_ASYNC and SND_FILENAME aren't defined, you're passing 0 Or 0 (i.e. 0) as the last parameter, which presumably isn't the right value.

    – Mathieu Guindon
    Nov 23 '18 at 15:54











  • What is your suggestion for code reform? Can you explain more?

    – stackoverflow2018
    Nov 23 '18 at 15:57











  • Those constants SND_ASYNC and SND_FILENAME are not declared. You can't just pass them like this since they will be treated as a variable and will default to 0. So you are essentially just running Call PlaySound("C:WindowsMediatada.wav, 0, 0) which is not doing what you want it to do. Check out this link at Chip Pearson's site where he has a good working example of this function with the constants declared in the code.

    – JNevill
    Nov 23 '18 at 16:11











  • Thank you @JNevill! The following line should be added to the code: Const SND_ASYNC = &H1

    – stackoverflow2018
    Nov 23 '18 at 16:20








1




1





Did you actually declare SND_ASYNC and SND_FILENAME?

– GSerg
Nov 23 '18 at 15:49







Did you actually declare SND_ASYNC and SND_FILENAME?

– GSerg
Nov 23 '18 at 15:49






1




1





Is Option Explicit specified? If SND_ASYNC and SND_FILENAME aren't defined, you're passing 0 Or 0 (i.e. 0) as the last parameter, which presumably isn't the right value.

– Mathieu Guindon
Nov 23 '18 at 15:54





Is Option Explicit specified? If SND_ASYNC and SND_FILENAME aren't defined, you're passing 0 Or 0 (i.e. 0) as the last parameter, which presumably isn't the right value.

– Mathieu Guindon
Nov 23 '18 at 15:54













What is your suggestion for code reform? Can you explain more?

– stackoverflow2018
Nov 23 '18 at 15:57





What is your suggestion for code reform? Can you explain more?

– stackoverflow2018
Nov 23 '18 at 15:57













Those constants SND_ASYNC and SND_FILENAME are not declared. You can't just pass them like this since they will be treated as a variable and will default to 0. So you are essentially just running Call PlaySound("C:WindowsMediatada.wav, 0, 0) which is not doing what you want it to do. Check out this link at Chip Pearson's site where he has a good working example of this function with the constants declared in the code.

– JNevill
Nov 23 '18 at 16:11





Those constants SND_ASYNC and SND_FILENAME are not declared. You can't just pass them like this since they will be treated as a variable and will default to 0. So you are essentially just running Call PlaySound("C:WindowsMediatada.wav, 0, 0) which is not doing what you want it to do. Check out this link at Chip Pearson's site where he has a good working example of this function with the constants declared in the code.

– JNevill
Nov 23 '18 at 16:11













Thank you @JNevill! The following line should be added to the code: Const SND_ASYNC = &H1

– stackoverflow2018
Nov 23 '18 at 16:20





Thank you @JNevill! The following line should be added to the code: Const SND_ASYNC = &H1

– stackoverflow2018
Nov 23 '18 at 16:20












1 Answer
1






active

oldest

votes


















0














Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As LongPtr, ByVal dwFlags As Long) As Boolean

Const SND_ASYNC = &H1

Private Sub CommandButton1_Click()
Call PlaySound("c:windowsmediatada.wav", 0, SND_ASYNC Or SND_FILENAME)
Msgbox "Process completed successfully."
End Sub





share|improve this answer





















  • 2





    Add Option Explicit at the top and your code stops compiling, because SND_FILENAME isn't declared anywhere. Either declare SND_FILENAME as well, or remove Or SND_FILENAME from the function call - it's doing exactly nothing right now.

    – Mathieu Guindon
    Nov 23 '18 at 16:49











  • The underscore "_" in your API declaration indicates an intentional line break or has to be removed otherwise.

    – T.M.
    Nov 23 '18 at 18:29














Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449434%2fmessage-box-and-sound-play-simultaneously-vba%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As LongPtr, ByVal dwFlags As Long) As Boolean

Const SND_ASYNC = &H1

Private Sub CommandButton1_Click()
Call PlaySound("c:windowsmediatada.wav", 0, SND_ASYNC Or SND_FILENAME)
Msgbox "Process completed successfully."
End Sub





share|improve this answer





















  • 2





    Add Option Explicit at the top and your code stops compiling, because SND_FILENAME isn't declared anywhere. Either declare SND_FILENAME as well, or remove Or SND_FILENAME from the function call - it's doing exactly nothing right now.

    – Mathieu Guindon
    Nov 23 '18 at 16:49











  • The underscore "_" in your API declaration indicates an intentional line break or has to be removed otherwise.

    – T.M.
    Nov 23 '18 at 18:29


















0














Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As LongPtr, ByVal dwFlags As Long) As Boolean

Const SND_ASYNC = &H1

Private Sub CommandButton1_Click()
Call PlaySound("c:windowsmediatada.wav", 0, SND_ASYNC Or SND_FILENAME)
Msgbox "Process completed successfully."
End Sub





share|improve this answer





















  • 2





    Add Option Explicit at the top and your code stops compiling, because SND_FILENAME isn't declared anywhere. Either declare SND_FILENAME as well, or remove Or SND_FILENAME from the function call - it's doing exactly nothing right now.

    – Mathieu Guindon
    Nov 23 '18 at 16:49











  • The underscore "_" in your API declaration indicates an intentional line break or has to be removed otherwise.

    – T.M.
    Nov 23 '18 at 18:29
















0












0








0







Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As LongPtr, ByVal dwFlags As Long) As Boolean

Const SND_ASYNC = &H1

Private Sub CommandButton1_Click()
Call PlaySound("c:windowsmediatada.wav", 0, SND_ASYNC Or SND_FILENAME)
Msgbox "Process completed successfully."
End Sub





share|improve this answer















Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As LongPtr, ByVal dwFlags As Long) As Boolean

Const SND_ASYNC = &H1

Private Sub CommandButton1_Click()
Call PlaySound("c:windowsmediatada.wav", 0, SND_ASYNC Or SND_FILENAME)
Msgbox "Process completed successfully."
End Sub






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 '18 at 17:44









GSerg

60.3k15108237




60.3k15108237










answered Nov 23 '18 at 16:22









stackoverflow2018stackoverflow2018

73




73








  • 2





    Add Option Explicit at the top and your code stops compiling, because SND_FILENAME isn't declared anywhere. Either declare SND_FILENAME as well, or remove Or SND_FILENAME from the function call - it's doing exactly nothing right now.

    – Mathieu Guindon
    Nov 23 '18 at 16:49











  • The underscore "_" in your API declaration indicates an intentional line break or has to be removed otherwise.

    – T.M.
    Nov 23 '18 at 18:29
















  • 2





    Add Option Explicit at the top and your code stops compiling, because SND_FILENAME isn't declared anywhere. Either declare SND_FILENAME as well, or remove Or SND_FILENAME from the function call - it's doing exactly nothing right now.

    – Mathieu Guindon
    Nov 23 '18 at 16:49











  • The underscore "_" in your API declaration indicates an intentional line break or has to be removed otherwise.

    – T.M.
    Nov 23 '18 at 18:29










2




2





Add Option Explicit at the top and your code stops compiling, because SND_FILENAME isn't declared anywhere. Either declare SND_FILENAME as well, or remove Or SND_FILENAME from the function call - it's doing exactly nothing right now.

– Mathieu Guindon
Nov 23 '18 at 16:49





Add Option Explicit at the top and your code stops compiling, because SND_FILENAME isn't declared anywhere. Either declare SND_FILENAME as well, or remove Or SND_FILENAME from the function call - it's doing exactly nothing right now.

– Mathieu Guindon
Nov 23 '18 at 16:49













The underscore "_" in your API declaration indicates an intentional line break or has to be removed otherwise.

– T.M.
Nov 23 '18 at 18:29







The underscore "_" in your API declaration indicates an intentional line break or has to be removed otherwise.

– T.M.
Nov 23 '18 at 18:29






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449434%2fmessage-box-and-sound-play-simultaneously-vba%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Paul Cézanne

UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

Angular material date-picker (MatDatepicker) auto completes the date on focus out