到Word文档中的程序。

以下是示例代码:

Sub ScanToWord()
    '声明变量
    Dim wApp As Word.Application
    Dim wDoc As Word.Document
    Dim wRange As Word.Range
    Dim sPath As String
    
    '创建Word对象
    Set wApp = CreateObject("Word.Application")
    wApp.Visible = True
    
    '创建文档
    Set wDoc = wApp.Documents.Add
    
    '创建范围
    Set wRange = wDoc.Range
    
    '调用扫描仪
    Dim wiaDialog As Object
    Set wiaDialog = CreateObject("WIA.CommonDialog")
    Dim wiaImage As Object
    Set wiaImage = wiaDialog.ShowAcquireImage
    '将扫描的图片保存到指定路径
    sPath = ThisWorkbook.Path & "\ScanImage.jpg"
    wiaImage.SaveFile sPath
    
    '插入图片到文档
    wRange.InlineShapes.AddPicture FileName:=sPath, LinkToFile:=False, SaveWithDocument:=True
    
    '释放对象
    Set wRange = Nothing
    Set wDoc = Nothing
    Set wApp = Nothing
    Set wiaImage = Nothing
    Set wiaDialog = Nothing
End Sub

运行该程序后,会弹出扫描仪的扫描窗口,扫描完毕后会将图片插入到新创建的Word文档中。注意需要将代码中的文件保存路径修改为自己需要保存的路径

使用VBA语言编写一个调用已安装扫描仪扫描图片并将扫描的图片插入

原文地址: http://www.cveoy.top/t/topic/foF4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录