+ Reply to Thread
Results 1 to 4 of 4

Modifying VBA code to add conditional element

Hybrid View

  1. #1
    Forum Contributor jonvanwyk's Avatar
    Join Date
    06-28-2010
    Location
    Iowa, USA
    MS-Off Ver
    Excel 2010
    Posts
    452

    Modifying VBA code to add conditional element

    I am currently using the code below to convert a cell range to a PDF file and automatically save it to a spot on a network drive with a predetermined name. How can I add a condition to this so that it only actually saves the PDF to that folder when the following conditions are met:

    E8 OR E10 OR E11 OR E13 = TRUE AND E17 OR E18 OR E19 OR E20 = TRUE

    Sub clicksubmit01()
    
        Dim FileName As String
        
        FileName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5)
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
                "S:\Folder Location\" & Cells(2, 2).Value & " - " & Cells(6, 2).Value & ".pdf", _
                Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
                :=False, OpenAfterPublish:=False
        Range("A1:D27").Select
        
    End Sub
    Last edited by jonvanwyk; 07-19-2011 at 10:55 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Modifying VBA code to add conditional element

    Something like:

    Sub clicksubmit01()
    Dim FileName As String
        
    If ([E8] = True Or [E10] = True Or [E11] = True Or [E13] = True) And _
      ([E17] = True Or [E18] = True Or [E19] = True Or [E20] = True) Then
        FileName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5)
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
                "S:\Folder Location\" & Cells(2, 2).Value & " - " & Cells(6, 2).Value & ".pdf", _
                Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
                :=False, OpenAfterPublish:=False
        Range("A1:D27").Select
    End If
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Modifying VBA code to add conditional element

    Sub snb()
      if ([E8]+[E10]+[E11]+[E13]) * ([E17]+ [E18] +[E19]+[E20]) >0 then ...
    end sub



  4. #4
    Forum Contributor jonvanwyk's Avatar
    Join Date
    06-28-2010
    Location
    Iowa, USA
    MS-Off Ver
    Excel 2010
    Posts
    452

    Re: Modifying VBA code to add conditional element

    Hey guys...thank you very much...your suggestions worked flawlessly. However, depending on the cells and true statements, sometimes I need the PDF to go to an email as an attachment instead of being saved to a network drive. How can I modify the above code to send the PDF to a specific email address when those conditions are met?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1