VBA

Hello all,
I have a vba code that must pick up an adobe illustrator file and generate ldf and tiff format, but that code is only working for ldf generation but not tiff.

Below is the code that is giving the error. for tif conversion.

Public Sub makeTiffFile()

’ Dim appPS As Photoshop.Application
’ Dim docPS As Photoshop.Document
Dim appPS As Object
Dim docPS As Object
Dim pdfOpenOption As Object
Dim trgFLS As Files
Dim tmpFL As File
Dim fExtension As String
Dim fName As String
Dim Ret As Boolean
Dim cnt As Integer
Dim chkFolder As MSForms.CheckBox

'On Error GoTo Err

Set appPS = CreateObject(“Illustrator.Application”)

'commented for testing for myself
'appPS.DisplayDialogs = psDisplayNoDialogs

appPS.Visible = False

'Set pdfOpenOption = CreateObject(“Illustrator.pdfOpenOptions”)
'pdfOpenOption.AntiAlias = True
'pdfOpenOption.CropPage = psArtBox
'pdfOpenOption.Mode = psGrayscale
'pdfOpenOption.Page = 1
'pdfOpenOption.Resolution = 300
'pdfOpenOption.SuppressWarnings = True

cnt = 0

If chkFolder.Tiff Then
Set trgFLS = WorkFolder.Files
Else
Set trgFLS = InFolder.Files
End If

For Each tmpFL In trgFLS

fName = FSO.GetBaseName(tmpFL.Path)
fExtension = FSO.GetExtensionName(tmpFL.Path)

If LCase(fExtension) = “ai” And chkFolder.Tiff Then
If chkFile(cnt).fileName & chkFile(cnt).fileType = fName And _
chkFile(cnt).TargetFlg Then

Set docPS = appPS.Open(tmpFL.Path, pdfOpenOption)
Else
'GoTo Retry_Err
End If

'ElseIf (LCase(fExtension) = “tif” Or LCase(fExtension) = “tiff”) Then

’ Set docPS = appPS.Open(tmpFL.Path)

'Else
'GoTo Retry_Err
'End If

If ResizeImageFile(appPS, docPS) Then

Call LogOutputMark(chkLog.LogSave, chkFile(cnt).fileName & “.” & fExtension, 2)
Else
Call LogOutputError(chkLog.LogSave, chkFile(cnt).fileName & “.” & fExtension, 2)
'GoTo Err
End If
End If

’ Call docPS.ChangeMode(PsChangeMode.psConvertToGrayscale)
Call docPS.ChangeMode(psConvertToGrayscale)

Call TwoTone(appPS)

Call SaveTiffFile(docPS, TiffFolder)

Call LogOutputMark(chkLog.LogSave, chkFile(cnt).fileName & “.” & fExtension, 1)

Call docPS.Close(psDoNotSaveChanges)
Set docPS = Nothing

'Next

'Retry_Err:
'cnt = cnt + 1

'Next

'appPS.DisplayDialogs = psDisplayAllDialogs

'PhotoshopI—¹
'appPS.Quit
’ Set appPS = Nothing
’ Set pdfOpenOption = Nothing
’ Exit Sub

'Err:

'If Not docPS Is Nothing Then
’ Call docPS.Close(psDoNotSaveChanges)
’ Set docPS = Nothing
'End If

'If Not tmpFL Is Nothing Then
’ Call LogOutputError(chkLog.LogSave, chkFile(cnt).fileName & “.” & fExtension, 1)
’ Set tmpFL = Nothing
'End If

'Resume Retry_Err

End Sub

Hi @shama93

Try this:

Public Sub MakeTiffFile()
    Dim appPS As Object
    Dim docPS As Object
    Dim trgFLS As Files
    Dim tmpFL As File
    Dim fExtension As String
    Dim fName As String
    Dim cnt As Integer
    Dim chkFolder As MSForms.CheckBox

    Set appPS = CreateObject("Illustrator.Application")
    appPS.Visible = False

    cnt = 0

    If chkFolder.Tiff Then
        Set trgFLS = WorkFolder.Files
    Else
        Set trgFLS = InFolder.Files
    End If

    For Each tmpFL In trgFLS
        fName = FSO.GetBaseName(tmpFL.Path)
        fExtension = LCase(FSO.GetExtensionName(tmpFL.Path))

        If fExtension = "ai" And chkFolder.Tiff Then
            If chkFile(cnt).fileName & chkFile(cnt).fileType = fName And chkFile(cnt).TargetFlg Then
                ' Set docPS = appPS.Open(tmpFL.Path, pdfOpenOption)
                ' Adjust the above line based on your actual requirements
            Else
                ' GoTo NextFile
            End If
        ElseIf fExtension = "tif" Or fExtension = "tiff" Then
            Set docPS = appPS.Open(tmpFL.Path)
        Else
            ' GoTo NextFile
        End If

        If Not docPS Is Nothing Then
            If ResizeImageFile(appPS, docPS) Then
                Call LogOutputMark(chkLog.LogSave, chkFile(cnt).fileName & "." & fExtension, 2)
            Else
                Call LogOutputError(chkLog.LogSave, chkFile(cnt).fileName & "." & fExtension, 2)
            End If

            ' Call docPS.ChangeMode(PsChangeMode.psConvertToGrayscale)
            Call docPS.ChangeMode(psConvertToGrayscale)
            Call TwoTone(appPS)
            Call SaveTiffFile(docPS, TiffFolder)
            Call LogOutputMark(chkLog.LogSave, chkFile(cnt).fileName & "." & fExtension, 1)
            Call docPS.Close(psDoNotSaveChanges)
            Set docPS = Nothing
        End If

NextFile:
        ' Increment the counter for the next file
        cnt = cnt + 1
    Next

    ' Cleanup
    appPS.Quit
    Set appPS = Nothing
End Sub

Hope it helps!!

Your tiff code was commented.

it’s giving error again

While modifying the code I did that.