ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   save clipboard as wmf (https://www.excelbanter.com/excel-programming/288464-save-clipboard-wmf.html)

Erich Neuwirth

save clipboard as wmf
 
I need a vba macro to save the clipboard contents as wmf file.
does anybody have code for doing this?

BrianB

save clipboard as wmf
 
Cannot do the .wmf file because MS Paint will only save a .bmp file
However this macro should give you an idea how to do it with you
application. You will probably have quite a bit of tweaking to do t
get it to work. Save your macro often.

Copy the picture in Excel and run the macro. After opening MSPaint wit
Shell(), it mimics the menu keystrokes required to paste the pictur
from the clipboard, save the file, and close MS Paint.

The macro tends to run too fast so delays have been put in to allo
time for things to happen in Paint as a result of SendKeys, otherwis
Sendkeys tries to send to Excel - often with odd results.

Be patient, and allow time for the macro to complete before doin
anything.

'---------------------------------------------
Sub SavePicture()
Dim MSPaint As String
Dim MyFileName As String
Dim Alt As String
'----------------------------
MyFileName = "Myfile.bmp"
'----------------------------
Alt = "%"
MSPaint = "C:\WINNT\system32\mspaint.exe"
retval = Shell(MSPaint, 1)
'- paste --------------------------
SendKeys Alt & "E", True ' edit
SendKeys "P", True 'paste
Application.Wait Now + TimeValue("00:00:02")
'- save file ------------------------
SendKeys Alt & "F" ' file
Application.Wait Now + TimeValue("00:00:01")
'-
SendKeys "A", True ' saveas
Application.Wait Now + TimeValue("00:00:01")
'-
SendKeys MyFileName, True 'file name
Application.Wait Now + TimeValue("00:00:02")
'-
SendKeys Alt & "S", True
DoEvents
Application.Wait Now + TimeValue("00:00:5")
'- close ----------------------------
SendKeys Alt & "{F4}", True
DoEvents
MsgBox ("File Saved.")
End Sub
'-- eop --------------------------------------

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 07:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com