通过Excel VBA操纵绘画

时间:2019-04-15 14:48:39

标签: excel vba

我现在想针对我的特定情况使用此部分宏。我有365个选项卡,我想从Excel复制一定范围的单元格(“非图表”)并将其粘贴到Paint。图像将保存在特定的文件夹中。

注意:我知道这个问题,但是到目前为止,这个问题还没有适当的答案:Operating Ms Paint using excel-VBA

我已经尝试了许多尝试和错误 (i)递归函数,其中每个工作表将由宏处理(选择一个范围) (2)如何打开Paint(使用shell执行)

现在,我被困住了:(可以用#引用示例代码程序)

(i)如何将图像保存为png并保存到特定位置(请参阅path_TargetFolder) (ii)将文件保存到该位置后如何关闭

Sub savepng()

Dim ws As Worksheet
Dim starting_ws As Worksheet

Dim path_Folder As String
Dim pathPaint
'All images are saved into this folder
path_TargetFolder = "C:\OtherFolder\"


Set starting_ws = ActiveSheet 'remember which worksheet is active in the beginning

'Recursive functions
For Each ws In ThisWorkbook.Worksheets
    ws.Activate
    'Select a range
    Range("B1:T11").Select
    Selection.Copy

    'Opens up the Paint Program
    pathPaint = Shell("c:\windows\system32\mspaint.exe", vbMaximizedFocus)
    'Send Ctrl V key to simulate paste from Excel
    Call SendKeys("^V")

   '#Save the files in png according to tab name
   '#Save the files in the path_TargetFolder
   '#Close the paint to prevent memory not enough
   '    Code Ends
Next

starting_ws.Activate 'activate the worksheet that was originally active

End Sub

预期结果是C:\ OtherFolder \必须具有365个png文件

0 个答案:

没有答案