excel - 如何打印图像?

标签 excel vba image printing

我想打印在用户窗体的框架中显示的图像。

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

形式:

enter image description here

单击按钮打开 Windows Office 打印对话框:

enter image description here

关于excel - 如何打印图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30990717/

相关文章:

vba - 运行时错误 1004 'Unable to get the PivotFields property of the PivotTable class'

excel - 如何在Excel中编辑图表的图例条目?

excel - 我可以在不打开 Excel 或 Word 等相关文件的情况下复制 VBA 代码吗?

由于直接引用范围而不是通过中间变量而导致 Excel VBA 运行时错误 450

用于打开和编辑多个 Powerpoint 文件的 VBA

excel - 创建一个集合作为字典的值

image - 查找裁剪后的相似图像

excel - 使用 rst.Fields 将多个单元格发送到我的 SharePoint

image - 带有图像的 tableviewer 中的奇怪对齐和布局

swift - 使用 Kingfisher,图像无法在 UITableView 中正确加载