Sep 10

Convert .snag files to .jpg

The following code converts .snag files into .jpg formats. This isn't directly supported by the SnagIt COM API, but I was able to hack it by way of SendKeys to get an image onto the clipboard. In a broader sense, I'm using this to convert .snag files to .jpg on the file, which I can then insert into blank PowerPoint slides for dynamically building presentations. SnagIt code appears to be scarce on the Internet, so I'm offering this as thanks to others that posted various aspects that I pieced together to accomplish this.

Sub SnagItAutomation()

    'Creates a SnagIt object (SnagIt 8 and later)
    Dim myImage As SNAGITLib.IImageCapture2
    Set myImage = CreateObject("SnagIt.ImageCapture")
    'List of .snag file names
    Dim myFiles(4) As String
    myFiles(0) = "image1"
    myFiles(1) = "image2"
    myFiles(2) = "image3"
    myFiles(3) = "image4"
    myFiles(4) = "image5"
    'Path to SnagIt exe file
    strProgramPath = "C:\Program Files (x86)\techsmith\Snagit 10\SnagitEditor.exe"
    'Path to image (.snag) files
    strInputPath = "I:\"
    'Path to where resulting .jpg files should be saved
    strOutputPath = "T:\pending\"
    For i = LBound(myFiles) To UBound(myFiles)
        'Opens image file in SnagIt editor
        Shell strProgramPath & " """ & strInputPath & myFiles(i) & ".snag"""
        'Forces Excel to finish the process before moving on
        'Activates SnagIt Editor
        AppActivate "SnagIt Editor"
        'Sends Ctrl-C to copy image to the clipboard
        SendKeys "^c"
        'Generates capture
        With myImage
            'Tells SnagIt to grab capture from the clipboard
           .Input = siiClipboard
            'Tells SnagIt that we want our output to be a file
           .Output = sioFile
           'Sets output path for file
           .OutputImageFile.Directory = strOutputPath
           'Sets specifies name for output file
           .OutputImageFile.Filename = myFiles(i)
           'Sets file type for output file
           .OutputImageFile.FileType = siftJPEG
           'Tells SnagIt to use our fixed file name as specified above
           .OutputImageFile.FileNamingMethod = sofnmFixed
            'Intiates the capture
       End With


    Set myImage = Nothing

End Sub