|
楼主 |
发表于 2023-2-4 20:32
|
显示全部楼层
这是AI给的一段示例代码,你可以参考下。
- Sub PlotWaveform()
- Dim WaveFile As String
- Dim Data() As Integer
- Dim i As Long
- 'prompt the user for the file name
- WaveFile = Application.GetOpenFilename("WAV Files (*.wav), *.wav")
- 'read the wave file into an array
- Open WaveFile For Binary Access Read As #1
- ReDim Data(LOF(1) \ 2 - 1) As Integer
- For i = 0 To UBound(Data)
- Get #1, , Data(i)
- Next i
- Close #1
- 'plot the waveform in a chart
- With Worksheets.Add
- With .Range("A1").Resize(UBound(Data) + 1)
- .Value = Application.Transpose(Data)
- With .Parent.Shapes.AddChart2(251, xlLine, .Left, .Top, .Width, .Height).Chart
- .SetSourceData Source:=.Range("A1").Resize(UBound(Data) + 1)
- .Axes(xlCategory).MajorUnit = (UBound(Data) + 1) \ 10
- .Axes(xlValue).MinimumScale = -32768
- .Axes(xlValue).MaximumScale = 32767
- End With
- End With
- End With
- End Sub
复制代码 |
|