我想打印在用户窗体的框架中显示的图像。
frame1.Picture = LoadPicture(spath & xPicture & ".jpg")
spath
是存储图片的完整路径。这显示了图片。
我想打印它。
是否有代码可以从用户表单执行此操作,或者是否有代码可以从文件位置打印它?
最佳答案
一种选择是通过 shell 命令调用 Windows 打印对话框。
示例:(完整代码)
Option Explicit
Private Declare Function apiShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long
Private Sub CommandButton1_Click()
Dim MyPicFile As String: MyPicFile = "C:\Users\PortlandRunner\Pictures\excel.jpg"
Call apiShellExecute(Application.hwnd, "print", MyPicFile, vbNullString, vbNullString, 0)
End Sub
Private Sub UserForm_Initialize()
Dim spath As String
spath = "C:\Users\PortlandRunner\Pictures\excel.jpg"
Image1.Picture = LoadPicture(spath)
End Sub
形式:
单击按钮打开 Windows Office 打印对话框:
关于excel - 如何打印图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30990717/