Skip to content

Instantly share code, notes, and snippets.

@wsgzao
Last active May 3, 2022 10:52
Show Gist options
  • Save wsgzao/961388689507df9ea2b2f728b343dea4 to your computer and use it in GitHub Desktop.
Save wsgzao/961388689507df9ea2b2f728b343dea4 to your computer and use it in GitHub Desktop.
使用宏自动将Excel中的数据发送到PPT中
Sub 自动将Excel中的数据发送到PPT中()
'1、declare variables
Dim rng As Excel.Range
Dim pp As PowerPoint.Application
Dim pppres As PowerPoint.Presentation
Dim ppslide As PowerPoint.Slide
'2、Open PowerPoint and create new presentation
Set pp = New PowerPoint.Application
Set pppres = pp.Presentations.Add
pp.Visible = msoTrue
'3、Add new slide as slide 1 and set focus to it
Set ppslide = pppres.Slides.Add(1, 11)
ppslide.Select
'4、Copy the rng as a picture
Set rng = Worksheets("3").Range("b2:f7")
rng.CopyPicture xlScreen, xlPicture
'5、Paste the picture and adjust its position
ppslide.Shapes.Paste.Select
With pp.ActiveWindow.Selection.ShapeRange
.Align msoAlignCenters, msoTrue
.Align msoAlignMiddles, msoTrue
.Top = 72 * 0.86
.Left = 72 * 5.97
.Height = 72 * 3.28
.Width = 72 * 6.96
End With
'6、Add the title to the slide
ppslide.Shapes.Title.TextFrame.TextRange.Text = "一季度业务员销量表"
'7、memory cleanup
Set pp = Nothing
Set pppres = Nothing
Set ppslide = Nothing
End Sub
‘https://github.com/areed1192/sigma_coding_youtube/tree/master/vba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment