<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://communities.bentley.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to convert TIF to JPG using VBA ExportRasterFile?</title><link>https://communities.bentley.com/products/programming/microstation_programming/f/microstation-programming---forum/224579/how-to-convert-tif-to-jpg-using-vba-exportrasterfile</link><description>I wrote a VBA code to convert TIF to JPG, but it does not work. I get run time error 5 when I run my code. Can someone help me? I&amp;#39;m using Microstation v8i. My code is below one. 
 RasterManager.ExportRasterFile sourcefilename:=fpath &amp;amp; &amp;quot;\&amp;quot; &amp;amp; fname, destinationfilename</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to convert TIF to JPG using VBA ExportRasterFile?</title><link>https://communities.bentley.com/thread/691769?ContentTypeID=1</link><pubDate>Mon, 17 Jan 2022 01:49:23 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:868b8753-8f1f-49fb-aaa7-c45c8e660074</guid><dc:creator>hirotaka nisimura</dc:creator><description>&lt;p&gt;I read MicrostationVBA.chm and tried some ways, then I could save JPEG from TIFF using ExportRasterfile. The string &amp;#39;JPEG(J)&amp;#39; is not wrong but I have to add some arguments to my code.&lt;/p&gt;
&lt;p&gt;RasterManager.ExportRasterFile sourcefilename:=fname, _&lt;br /&gt; destinationfilename:=outname, _&lt;br /&gt; NewFormatSpecifier:=oRF, _&lt;br /&gt; NewColorModeSpecifier:=oColor, _&lt;br /&gt; NewCompressionModeSpecifier:=oCOMPRESS&lt;/p&gt;
&lt;p&gt;I got RasterFormat from another JPEG raster. And I got ColorMode and CompressionMode from it, then I set them as the arguments for ExortRasterFile.&lt;/p&gt;
&lt;p&gt;Then I excuted my improved code, it made JPEG from TIFF.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to convert TIF to JPG using VBA ExportRasterFile?</title><link>https://communities.bentley.com/thread/691762?ContentTypeID=1</link><pubDate>Mon, 17 Jan 2022 01:20:57 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:5e3acd14-bc31-4c53-933f-527682835a3a</guid><dc:creator>hirotaka nisimura</dc:creator><description>&lt;p&gt;Thank you Jon. I checked the filename. In the case that I set &amp;#39;JPEG&amp;#39; for Raster, the new file was saved. But it was TIFF, not JPEG format.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And I chekced RasterFormats class using your code.&amp;nbsp;As the result, The string of RasterFormat for JPEG is &amp;#39;JPEG(J)&amp;#39; so I tried again. But it don&amp;#39;t work.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to convert TIF to JPG using VBA ExportRasterFile?</title><link>https://communities.bentley.com/thread/691663?ContentTypeID=1</link><pubDate>Fri, 14 Jan 2022 14:30:58 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:bdaf60ec-1d9f-4915-9f84-496ec4fa8668</guid><dc:creator>Jon Summers</dc:creator><description>[quote userid="923155" url="~/products/programming/microstation_programming/f/microstation-programming---forum/224579/how-to-convert-tif-to-jpg-using-vba-exportrasterfile"]I get run time error 5[/quote]
&lt;p&gt;Add some &lt;code&gt;Debug&lt;/code&gt; statements to help find the problem.&lt;/p&gt;
&lt;pre&gt;Const Backslash As String = &amp;quot;\&amp;quot;&lt;/pre&gt;
&lt;pre&gt;Dim source As String
source = fpath &amp;amp; Backslash &amp;amp; fName
Debug.Print &amp;quot;Source=&amp;quot; &amp;amp; source&lt;/pre&gt;
&lt;pre&gt;Dim raster As String
raster = fpath &amp;amp; Backslash &amp;amp; fso.GetBaseName(fname) &amp;amp; &amp;quot;.jpg&amp;quot;
Debug.Print &amp;quot;Raster=&amp;quot; &amp;amp; raster&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;Debug.Print&lt;/code&gt; statement prints to the VBA &lt;em&gt;Immediate&lt;/em&gt; window.&amp;nbsp; Are those valid file names?&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;RasterFormats&lt;/code&gt; class is not well-documented.&amp;nbsp; It&amp;#39;s not clear whether &lt;code&gt;JPEG(J)&lt;/code&gt; is a valid search criterion.&amp;nbsp; The sole example I can find is...&lt;/p&gt;
&lt;pre&gt; Set oFormat = RasterManager.RasterFormats.Find(&amp;quot;TI~FF&amp;quot;)
&lt;/pre&gt;
&lt;p&gt;This always fails...&lt;/p&gt;
&lt;pre&gt;Sub TestRaster()
    Dim rm As RasterManager
    Set rm = RasterManager
    Dim oFormat As raster
    Dim formatName As String
    formatName = &amp;quot;JPEG(J)&amp;quot;
    Set oFormat = rm.RasterFormats.Find(formatName)
    If oFormat Is Nothing Then
        Debug.Print &amp;quot;Invalid format name &amp;quot; &amp;amp; formatName
    Else
        Debug.Print &amp;quot;Format name &amp;quot; &amp;amp; formatName &amp;amp; &amp;quot; is valid&amp;quot;
    End If
End Sub
&lt;/pre&gt;
&lt;p&gt;However, &amp;quot;JPEG&amp;quot; is valid.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s how to list all raster formats...&lt;/p&gt;
&lt;pre&gt;Sub TraceRasterFormats()
    Dim oFormat As RasterFormat
    Dim oFormats As RasterFormats
    Dim nFormat As Long
    nFormat = 1
    Dim msg     As String
    Set oFormats = RasterManager.RasterFormats
    For Each oFormat In oFormats
        msg = &amp;quot;Raster Format [" &amp;amp; CStr(nFormat) &amp;amp; "] = &amp;#39;&amp;quot; &amp;amp; oFormat.ToString() &amp;amp; &amp;quot;&amp;#39;&amp;quot;
        ShowMessage msg, msg, msdMessageCenterPriorityDebug
        Debug.Print msg
        nFormat = 1 + nFormat
    Next
End Sub
&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>