Forgive me, but what about this script makes it not want to work with X6? I run the exact same script through X8 all the time, and it works perfectly. Down close to the bottom of the script, I have highlighted where the Debugger highlights the script when it fails in X6.
Public Sub MBGen()Dim intCount1 As LongDim intCount2 As LongDim strRootDir As StringDim strBlankDir As StringDim strMBDir As StringDim strBlankFiles As StringDim strMBFiles As StringDim strCdrSave As StringDim strBaseFile As StringstrRootDir = "P:\MB\"strBlankDir = strRootDir & "blanks\"strMBDir = strRootDir & "MB\"strWebDir = strRootDir & "out\web\"strCdrDir = strRootDir & "out\cdr\"'Create a dynamic array variable, and then declare its initial sizeDim arrBlanks() As StringDim arrMB() As StringReDim arrBlanks(1000)ReDim arrMB(1000)'Loop through all the files in the MB directory by using Dir$ functionstrMBFiles = Dir$(strMBDir & "*.png")Do While strMBFiles <> ""arrMB(intCount1) = Left(strMBFiles, Len(strMBFiles) - 4)'arrMB(intCount1) = Replace(strMBFiles, ".PNG", "")strMBFiles = Dir$intCount1 = intCount1 + 1'Debug.Print intCount1Loop'Loop through all the files in the Blanks directory by using Dir$ functionstrBlankFiles = Dir$(strBlankDir & "*.cdr")Do While strBlankFiles <> ""'arrBlanks(intCount2) = Replace(strBlankFiles, ".cdr", "")arrBlanks(intCount2) = Left(strBlankFiles, Len(strBlankFiles) - 4)strBlankFiles = Dir$intCount2 = intCount2 + 1'Debug.Print intCount2Loop'Reset the size of the array without losing its values by using Redim PreserveReDim Preserve arrBlanks(intCount2 - 1)ReDim Preserve arrMB(intCount1 - 1)' To prove it worked you could run the following:For intCount2 = 0 To UBound(arrMB)For intCount1 = 0 To UBound(arrBlanks)strCdrSave = strCdrDir & arrMB(intCount2) & "-" & arrBlanks(intCount1) & ".cdr"strPngSave = strWebDir & arrMB(intCount2) & "-" & arrBlanks(intCount1) & ".png"strBaseFile = strBlankDir & arrBlanks(intCount1) & ".cdr"If Dir$(strCdrSave) = "" Then'Debug.Print writes the results to the Immediate window (press Ctrl + G to view it)''Debug.Print arrMB(intCount2) & " " & arrBlanks(intCount1)'open base filecdrOpen (strBaseFile)
'I'm making changes here on 4/16/19'ItemImage (strMBDir & arrMB(intCount2))''**********************************************''this was the original line on 4/16ItemImage (strMBDir & arrMB(intCount2) & ".png")'**********************************************'Debug.Print ("Saving " & arrMB(intCount2) & "-" & arrBlanks(intCount1))ActiveDocument.SaveAs (strCdrSave)Debug.Print ("Exporting " & arrMB(intCount2) & "-" & arrBlanks(intCount1))'export the pngpngExport (strPngSave)'close the file, rinse, lather, and repeatActiveDocument.CloseEnd IfNext intCount1Next intCount2End SubPrivate Sub pngExport(ByVal strExport As String)ActivePage.Shapes.All.CreateSelection' jpgW = 960' jpgH = 1200Set s = ActiveSelectionsw = s.SizeWidthsHght = s.SizeHeightIf sw > sHght Then'OLD CODE'ratio = sHght / swjpgW = 1000jpgH = jpgW * ratioElse'NEW CODE'jpgW = ((1000 * sw) / sHght)jpgH = 1000End If
'jpgH = 1200'jpgW = ((jpgH * sw) / sHght)Set expflt = ActiveDocument.ExportBitmap(strExport, cdrPNG, cdrSelection, cdrRGBColorImage, jpgW, jpgH, 450, 450, cdrNormalAntiAliasing, False, True, True, False, cdrCompressionNone)With expflt.Interlaced = True.Transparency = 0.invertmask = False.Color = 0.FinishEnd WithEnd SubPrivate Sub cdrOpen(ByVal strCDR As String)Dim openopt As StructOpenOptionsSet openopt = CreateStructOpenOptionsWith openopt.ColorConversionOptions.SourceColorProfileList = "sRGB IEC61966-2.1,U.S. Web Coated (SWOP) v2,Dot Gain 20%".TargetColorProfileList = "sRGB IEC61966-2.1,U.S. Web Coated (SWOP) v2,Dot Gain 20%"End WithDim doc1 As DocumentSet doc1 = OpenDocumentEx(strCDR, openopt)End SubPrivate Sub ItemImage(ByVal strMBFile As String)Dim impopt As StructImportOptionsSet impopt = CreateStructImportOptionsWith impopt.Mode = cdrImportFull.MaintainLayers = TrueWith .ColorConversionOptions.SourceColorProfileList = "sRGB IEC61966-2.1,U.S. Web Coated (SWOP) v2,Dot Gain 20%".TargetColorProfileList = "sRGB IEC61966-2.1,U.S. Web Coated (SWOP) v2,Dot Gain 20%"End WithEnd WithDim impflt As ImportFilterSet impflt = ActiveLayer.ImportEx(strMBFile, cdrPNG, impopt)impflt.FinishDim s1 As ShapeSet s1 = ActiveShapeActiveLayer.Shapes(1).Move -3.061949, -2.794587ActiveDocument.ReferencePoint = cdrCenterActiveLayer.Shapes(1).SetPosition -0.3, 9.35End Sub
All4U,
I was able to run the script in X6 without an issue. What is the error message it is showing?
-Shelby