Consulting

Results 1 to 4 of 4

Thread: Shorten loop using boolean

  1. #1

    Shorten loop using boolean

    Hello everyone
    I have a loop that do same procedure twice but slightly different .. and I need to use boolean to shorten those lines
        For i = 0 To PNum - 1 Step 2        Set newPDF = CreateObject("AcroExch.pdDoc")
            newPDF.Create
            NewName = F & "Txp " & Cells(r, 3).Value & ".pdf"
            newPDF.InsertPages -1, PDDoc, i, 1, 0
            newPDF.Save 1, NewName
            newPDF.Close
            Set newPDF = Nothing
            
            Set newPDF = CreateObject("AcroExch.pdDoc")
            newPDF.Create
            NewName = F & "Vsd " & Cells(r, 3).Value & ".pdf"
            newPDF.InsertPages -1, PDDoc, i + 1, 1, 0
            newPDF.Save 1, NewName
            newPDF.Close
            Set newPDF = Nothing
            
            r = r + 1
        Next i
    I tried to use boolean and use also If i Mod 2 but couldn't figure it out ..
    Can you help me please?

  2. #2
    Thanks a lot
    While i am trying I could figure it out
        For i = 0 To PNum - 1
            Set newPDF = CreateObject("AcroExch.pdDoc")
            newPDF.Create
            If i Mod 2 = 0 Then
                NewName = F & "Txp " & Cells(r, 3).Value & ".pdf"
            Else
                NewName = F & "Vsd " & Cells(r, 3).Value & ".pdf"
                r = r + 1
            End If
            newPDF.InsertPages -1, PDDoc, i, 1, 0
            newPDF.Save 1, NewName
            newPDF.Close
            Set newPDF = Nothing
        Next i
    Thank you very much

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    Cells(0, 3) doesn't exist
    F has no value
    Use with ... end With
    Variable r is redundant, because i=r

  4. #4
    Thanks a lot snb for reply
    In fact this is part of whole code and r is changeable ..
    Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •