Excel (VBA) |
![]() ![]() |
(Windows 10全般 : Microsoft 365)
エクセルのセル範囲をパワポに貼り付けたときの解像度が足りない
投稿日時: 22/06/12 16:21:11
投稿者: ip8bk
|
---|---|
いつもお世話になっております。
Option Explicit Sub test11() Dim PP As PowerPoint.Application Dim prs As PowerPoint.Presentation Dim sld As PowerPoint.Slide Dim shp As PowerPoint.Shape Dim FSO As Scripting.FileSystemObject Dim Fil As Scripting.File Dim rng As Variant Set PP = CreateObject("PowerPoint.Application") Set FSO = CreateObject("Scripting.FileSystemObject") Set prs = PP.Presentations.Add Set rng = Range("a1:ad30") rng.Copy Set sld = prs.Slides.Add(prs.Slides.Count + 1, ppLayoutBlank) With sld .FollowMasterBackground = msoFalse With .Background.Fill .TwoColorGradient Style:=msoGradientHorizontal, variant:=2 .ForeColor.RGB = RGB(255, 255, 255) .BackColor.RGB = RGB(204, 255, 255) End With End With prs.PageSetup.SlideWidth = 500 prs.PageSetup.SlideHeight = 500 sld.Select sld.Shapes.PasteSpecial DataType:=ppPasteBitmap, link:=msoFalse Set shp = sld.Shapes(1) With shp .LockAspectRatio = True '縦横比を固定 '挿入した画像をスライドのサイズに合わせる If .Width > .Height Then .Width = prs.PageSetup.SlideWidth Else .Height = prs.PageSetup.SlideHeight End If .Select End With '画像をスライド中央に配置 With PP.ActiveWindow.Selection.ShapeRange .Align msoAlignCenters, True .Align msoAlignMiddles, True End With With sld.SlideShowTransition .AdvanceOnClick = msoTrue .AdvanceOnTime = msoTrue .AdvanceTime = 0.1 End With End Sub |
![]() |
投稿日時: 22/06/12 22:59:55
投稿者: MMYS
|
---|---|
VBAコード以前に、ご希望の動作が、手作業で確認済みですか。
|
![]() |
投稿日時: 22/06/13 11:53:15
投稿者: Suzu
|
---|---|
既に MMYS さん からも在りますが
引用: との事でしたが、コードを作成している時間を考えると、地道の方が早かったのでは とも思います 画像ソフトであれば、グラデーションも背景レイヤ につけ、その中央等に本来の画像を重ねれば良い話。 やりたい素工程 は何なのか、それを効率化する為にどんな事が自動化できそうか? その為にどんなソフトを使うか 全体観を含め、検討してはどうかと思います。 |
![]() |
投稿日時: 22/06/13 12:39:52
投稿者: ip8bk
|
---|---|
ご回答ありがとうございます。
引用: 下記のコードで元サイズを調整するようにしました。 なのでサイズを合わせるコードは最終的に削除する予定です。 Dim rng As Excel.Range, rg As Range Set rng = Range("a1:ad30") Dim a As Range For Each a In rng.Columns With a .ColumnWidth = 5 .RowHeight = .Width End With Next まだ外周の揺らぎが気になりますので、何かご教示いただけることがございましたら、よろしくお願い致します。 Option Explicit Sub test11() Application.ScreenUpdating = False ActiveWindow.DisplayGridlines = False Dim PP As PowerPoint.Application Dim prs As PowerPoint.Presentation Dim sld As PowerPoint.Slide Dim shp As PowerPoint.Shape Dim FSO As Scripting.FileSystemObject Dim Fil As Scripting.File Dim rng As Excel.Range, rg As Range Set rng = Range("a1:ad30") Set rg = Range("h8:x22") Dim a As Range For Each a In rng.Columns With a .ColumnWidth = 5 .RowHeight = .Width End With Next Set PP = CreateObject("PowerPoint.Application") Set FSO = CreateObject("Scripting.FileSystemObject") Set prs = PP.Presentations.Add Dim rgrd As Excel.RectangularGradient Dim cs As Excel.ColorStop PP.ActiveWindow.WindowState = 2 Dim bkr As Integer, bkg As Integer, bkb As Integer bkr = Range("hr" & Range("hw89") + 89).Value bkg = Range("hs" & Range("hw89") + 89).Value bkb = Range("ht" & Range("hw89") + 89).Value Dim i As Integer For i = 1 To 2 '塗りつぶしの設定 With rg.Interior '塗りつぶしのパターンを矩形グラデーションに .Pattern = xlPatternRectangularGradient '矩形グラデーションの場合、Gradient プロパティは Set rgrd = .Gradient End With ' 矩形グラデーションの設定 With rgrd 'グラデーションの収束先となるポイント/ベクトルの指定 If i Mod 2 = 0 Then .RectangleTop = 0.75 .RectangleLeft = 0.75 .RectangleRight = 0.75 .RectangleBottom = 0.75 Else .RectangleTop = 0.25 .RectangleLeft = 0.25 .RectangleRight = 0.25 .RectangleBottom = 0.25 End If '全てのカラーストップポイントをクリア .ColorStops.Clear '0%の位置にカラーストップポイントを追加 Set cs = .ColorStops.Add(0) cs.Color = RGB(240, 240, 170) Set cs = Nothing '20%の位置にカラーストップポイントを追加 Set cs = .ColorStops.Add(0.2) cs.Color = RGB(195, 180, 100) Set cs = Nothing '100%の位置にカラーストップポイントを追加 Set cs = .ColorStops.Add(1) cs.Color = RGB(150, 120, 30) Set cs = Nothing End With Set rgrd = Nothing Application.ScreenUpdating = True Application.Wait [Now() + "00:00:00.2"] With Worksheets("Sheet1") rng.Copy Dim ws As Worksheet Set ws = ThisWorkbook.Worksheets("sheet1") Set sld = prs.Slides.Add(prs.Slides.Count + 1, ppLayoutBlank) Application.ActiveWindow.WindowState = ppWindowMinimized prs.PageSetup.SlideWidth = 1350 prs.PageSetup.SlideHeight = 1350 sld.Select sld.Shapes.PasteSpecial DataType:=ppPasteBitmap, link:=msoFalse Set shp = sld.Shapes(1) With shp .LockAspectRatio = True '縦横比を固定 '挿入した画像をスライドのサイズに合わせる If .Width > .Height Then .Width = prs.PageSetup.SlideWidth Else .Height = prs.PageSetup.SlideHeight End If .Select End With '画像をスライド中央に配置 With PP.ActiveWindow.Selection.ShapeRange .Align msoAlignCenters, True .Align msoAlignMiddles, True End With End With With sld.SlideShowTransition .AdvanceOnClick = msoTrue .AdvanceOnTime = msoTrue .AdvanceTime = 0.1 End With Next i Dim WSH As Object Set WSH = CreateObject("WScript.Shell") Dim outputPath As String outputPath = WSH.SpecialFolders("MyDocuments") & "\2022png" & "\anime" Dim lastrow As Integer lastrow = WorksheetFunction.CountA(Worksheets("sheet2").Columns(1)) + 1 Worksheets("sheet2").Cells(lastrow, 1) = 1 Dim file_name As String file_name = "anime#" & lastrow & ".gif" outputPath = outputPath & "\" & file_name Set WSH = Nothing Application.Wait (Now + TimeValue("00:00:10")) '10秒待機 prs.SaveAs Filename:=outputPath, FileFormat:=40 PP.Activate PP.ActiveWindow.WindowState = 2 On Error Resume Next Do While PP.Presentations.Count > 0 Application.Wait (Now + TimeValue("00:00:3")) '10秒待機 prs.Saved = False prs.Close Loop On Error GoTo 0 PP.Quit Set shp = Nothing Set sld = Nothing Set prs = Nothing Set PP = Nothing Set Fil = Nothing Set FSO = Nothing Set rg = Nothing ActiveWindow.DisplayGridlines = True Application.ScreenUpdating = True End Sub |
![]() |
投稿日時: 22/06/13 17:08:21
投稿者: Suzu
|
---|---|
結局 解像度の話は解決したと言うことで良いのでしょうか?
引用: 手元 365 ではないので、MP4を作成し確認しましたが、 何を【ゆらぎ】と言っているのか 確認できませんでした。 引用: PowerPointの段階でそのゆらぎが発生するのか 手動で各フォーマットの動画にした時にはどうなのか カラーストップポイントを2つではなく、1つの時はどうなのか Excel から 画像としてコピペするのではなく、PowerPoint側で Shapeとして作成たらどうなのか 確認できる事は沢山あります。 |
![]() |
投稿日時: 22/06/14 07:32:29
投稿者: ip8bk
|
---|---|
引用: ご回答ありがとうございます。 すみません、揺らぎという表現は正しくなかったです。私が揺らぎと言っていたのは、砂嵐のような粒粒が動いている状態のことです。再現性ありませんでしょうか? よくわかっていませんが、解像度が低いことが原因で問題が起きていると考えています。 そのため、まだ解決できていません。 引用: 説明不足で申し訳ありません。パワポの時点ではすごくきれいですが、アニメーションGIFにすると荒さが目立つように見えます。なので、パワポから変換するときの問題と思っています。コードを途中でストップして手作業で保存しても同様の問題が起きます。 また、下記のコードでは問題は起きません。 Option Explicit Sub test11() Application.ScreenUpdating = False ActiveWindow.DisplayGridlines = False Dim PP As PowerPoint.Application Dim prs As PowerPoint.Presentation Dim sld As PowerPoint.Slide Dim shp As PowerPoint.Shape Dim FSO As Scripting.FileSystemObject Dim Fil As Scripting.File Dim rng As Excel.Range, rg As Range Set rng = Range("a1:ad30") Set rg = Range("h8:x22") Dim a As Range For Each a In rng.Columns With a .ColumnWidth = 5 .RowHeight = .Width End With Next Set PP = CreateObject("PowerPoint.Application") Set FSO = CreateObject("Scripting.FileSystemObject") Set prs = PP.Presentations.Add Dim rgrd As Excel.RectangularGradient Dim cs As Excel.ColorStop PP.ActiveWindow.WindowState = 2 Dim bkr As Integer, bkg As Integer, bkb As Integer bkr = Range("hr" & Range("hw89") + 89).Value bkg = Range("hs" & Range("hw89") + 89).Value bkb = Range("ht" & Range("hw89") + 89).Value Dim i As Integer For i = 1 To 2 '塗りつぶしの設定 With rg.Interior '塗りつぶしのパターンを矩形グラデーションに .Pattern = xlPatternRectangularGradient '矩形グラデーションの場合、Gradient プロパティは Set rgrd = .Gradient End With ' 矩形グラデーションの設定 With rgrd 'グラデーションの収束先となるポイント/ベクトルの指定 ' If i Mod 2 = 0 Then .RectangleTop = 0.75 .RectangleLeft = 0.75 .RectangleRight = 0.75 .RectangleBottom = 0.75 ' Else ' .RectangleTop = 0.25 ' .RectangleLeft = 0.25 ' .RectangleRight = 0.25 ' .RectangleBottom = 0.25 ' End If '全てのカラーストップポイントをクリア .ColorStops.Clear '0%の位置にカラーストップポイントを追加 Set cs = .ColorStops.Add(0) cs.Color = RGB(240, 240, 170) Set cs = Nothing '20%の位置にカラーストップポイントを追加 Set cs = .ColorStops.Add(0.2) cs.Color = RGB(195, 180, 100) Set cs = Nothing '100%の位置にカラーストップポイントを追加 Set cs = .ColorStops.Add(1) cs.Color = RGB(150, 120, 30) Set cs = Nothing End With Set rgrd = Nothing Application.ScreenUpdating = True Application.Wait [Now() + "00:00:00.2"] With Worksheets("Sheet1") rng.Copy Dim ws As Worksheet Set ws = ThisWorkbook.Worksheets("sheet1") Set sld = prs.Slides.Add(prs.Slides.Count + 1, ppLayoutBlank) Application.ActiveWindow.WindowState = ppWindowMinimized prs.PageSetup.SlideWidth = 1350 prs.PageSetup.SlideHeight = 1350 sld.Select sld.Shapes.PasteSpecial DataType:=ppPasteBitmap, link:=msoFalse Set shp = sld.Shapes(1) With shp .LockAspectRatio = True '縦横比を固定 '挿入した画像をスライドのサイズに合わせる If .Width > .Height Then .Width = prs.PageSetup.SlideWidth Else .Height = prs.PageSetup.SlideHeight End If .Select End With '画像をスライド中央に配置 With PP.ActiveWindow.Selection.ShapeRange .Align msoAlignCenters, True .Align msoAlignMiddles, True End With End With With sld.SlideShowTransition .AdvanceOnClick = msoTrue .AdvanceOnTime = msoTrue .AdvanceTime = 0.1 End With Next i Dim WSH As Object Set WSH = CreateObject("WScript.Shell") Dim outputPath As String outputPath = WSH.SpecialFolders("MyDocuments") & "\2022png" & "\anime" Dim lastrow As Integer lastrow = WorksheetFunction.CountA(Worksheets("sheet2").Columns(1)) + 1 Worksheets("sheet2").Cells(lastrow, 1) = 1 Dim file_name As String file_name = "anime#" & lastrow & ".gif" outputPath = outputPath & "\" & file_name Set WSH = Nothing Application.Wait (Now + TimeValue("00:00:10")) '10秒待機 prs.SaveAs Filename:=outputPath, FileFormat:=40 PP.Activate PP.ActiveWindow.WindowState = 2 On Error Resume Next Do While PP.Presentations.Count > 0 Application.Wait (Now + TimeValue("00:00:3")) '10秒待機 prs.Saved = False prs.Close Loop On Error GoTo 0 PP.Quit Set shp = Nothing Set sld = Nothing Set prs = Nothing Set PP = Nothing Set Fil = Nothing Set FSO = Nothing Set rg = Nothing ActiveWindow.DisplayGridlines = True Application.ScreenUpdating = True End Sub |
![]() |
投稿日時: 22/06/14 09:01:24
投稿者: Suzu
|
---|---|
当方では、GIF作成できない環境です。MP4では再現できません。
|
![]() |
投稿日時: 22/06/14 10:45:44
投稿者: sk
|
---|---|
引用: 引用: 引用: GIF フォーマットで保存しようとしている限りは無理ではないでしょうか。 GIF フォーマットの特性上、特に高解像度の写真やグラデーションを扱う 画像ではどうしても減色処理が発生し、大抵の場合画質は低下しますので。 |
![]() |
投稿日時: 22/06/20 07:05:18
投稿者: ip8bk
|
---|---|
ご回答いただきました皆様ありがとうございました。
|