play mid file while sheets are imported.

geno32080

Board Regular
Joined
Jan 23, 2020
Messages
107
Office Version
  1. 2013
Platform
  1. Windows
This may sound crazy, but, as we all love experimenting with excel boundaries here goes.
I have a command button that imports files and pastes to individual sheets, this process takes about 5 seconds, I have this code that starts and stops a mid file, is it possible to have the mid file play while the files are importing and pasting? The mid file needs to run 5 seconds I can adjust it once I get it to work with the button.

This works when I run the sub manually. I would like to intergrate it with Private Sub CommandButton below, that's an abbreviated version, it does a total of 8 sheets. Thanks for taking the time. Help is always appreciated. I have a presentation coming up to show the workbook, hoping the music will liven up the presentation a bit.

Private Declare Function mciExecute Lib "winmm.dll" _
(ByVal lpstrCommand As String) As Long

Sub Midi(action As String, midiFilename)
If Dir(midiFilename) = "" Then
MsgBox midiFilename & vbCrLf & "Does Not Exist."
Exit Sub
End If
mciExecute action & " " & midiFilename
End Sub

Sub PlayMIDI()
Dim mf As String
mf = "C:\Windows\Media\onestop.mid"
Midi "play", mf
End Sub

Sub StopMIDI()
Dim mf As String
mf = "C:\Windows\Media\onestop.mid"
Midi "stop", mf
End Sub

Private Sub CommandButton1_Click()
Dim sourceworkbook As Workbook

Set sourceworkbook = Workbooks.Open("C:\JEN FOLDER\IMPORT\Jacksonville.csv")
sourceworkbook.Sheets("Jacksonville").Range("A3:S98").Copy
ThisWorkbook.Worksheets("jax").Range("B9").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
sourceworkbook.Close
Set sourceworkbook = Nothing

Me.Hide
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
This may sound crazy, but, as we all love experimenting with excel boundaries here goes.
I have a command button that imports files and pastes to individual sheets, this process takes about 5 seconds, I have this code that starts and stops a mid file, is it possible to have the mid file play while the files are importing and pasting? The mid file needs to run 5 seconds I can adjust it once I get it to work with the button.

This works when I run the sub manually. I would like to intergrate it with Private Sub CommandButton below, that's an abbreviated version, it does a total of 8 sheets. Thanks for taking the time. Help is always appreciated. I have a presentation coming up to show the workbook, hoping the music will liven up the presentation a bit.

1. Private Declare Function mciExecute Lib "winmm.dll" _
(ByVal lpstrCommand As String) As Long

2. Sub Midi(action As String, midiFilename)
If Dir(midiFilename) = "" Then
MsgBox midiFilename & vbCrLf & "Does Not Exist."
Exit Sub
End If
mciExecute action & " " & midiFilename
End Sub

3. Sub PlayMIDI()
Dim mf As String
mf = "C:\Windows\Media\onestop.mid"
Midi "play", mf
End Sub

4. Sub StopMIDI()
Dim mf As String
mf = "C:\Windows\Media\onestop.mid"
Midi "stop", mf
End Sub

Private Sub CommandButton1_Click()
add Call playmidi here
Dim sourceworkbook As Workbook

Set sourceworkbook = Workbooks.Open("C:\JEN FOLDER\IMPORT\Jacksonville.csv")
sourceworkbook.Sheets("Jacksonville").Range("A3:S98").Copy
ThisWorkbook.Worksheets("jax").Range("B9").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
sourceworkbook.Close
Set sourceworkbook = Nothing
add Call stopmidi here
Me.Hide
End Sub
Okay I figured it out, it was no where near as hard as I imagined it would be.
Step One, Create a module and put all 4 of the coding there,
Step Two, Add Call PlayMidi
Works great, adds a little drama while the sheets load.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,630
Messages
6,120,634
Members
448,973
Latest member
ChristineC

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top