Hello. Novice VBA user here. I have this code, which works, to email an entire spreadsheet, however I want it to only email the visible cells and NOT the hidden ones. How do I do this?
' This routine will send the Project Leader Project Status Sheet
'
Private Sub SendProjectLeaderProjectStatusToISOEmail(Email As String)
'Setting up the Excel variables.
Dim olApp As Object
Dim olMailItm As Object
Dim iCounter As Integer
Dim reportperiod As String
Dim slin As String
Dim budget As String
Dim currentmonthlytotal As String
Dim total As String
Dim balance As String
Dim percentcomplete As String
Dim popstart As String
Dim popend As String
Dim followonproject As String
Dim projectleaderemail As String
Dim reportperiodLength As String
Dim slinLength As String
Dim budgetLength As String
Dim currentmonthlytotalLength As String
Dim totalLength As String
Dim balanceLength As String
Dim percentcompleteLength As String
Dim popstartLength As String
Dim popendLength As String
Dim followonprojectLength As String
Dim projectleaderemailLength As String
Dim spaceString As String
'Create the Outlook application and the empty email.
Set olApp = CreateObject("Outlook.Application")
Set olMailItm = olApp.CreateItem(0)
iCounter = 4
'Select the ActiveCell on that worksheet
Set rng = ActiveCell
'Using the email, add multiple recipients, using a list of addresses in column A.
With olMailItm
'Do additional formatting on the BCC and Subject lines, add the body text from the spreadsheet, and send.
.Sender = Email
.To = Email
.Subject = "Project Leader Project Status" + Format(Now, " YYYY-MM-DD")
.HTMLBody = "<P STYLE='font-family:Courier New;font-size:8pt;color: rgb(0,0,0)'><br><pre>"
Do While Sheets("Project Leader Project Status").Cells(iCounter, 1).Text <> ""
reportperiod = Sheets("Project Leader Project Status").Cells(iCounter, 1).Text
slin = Sheets("Project Leader Project Status").Cells(iCounter, 1).Text
budget = Sheets("Project Leader Project Status").Cells(iCounter, 2).Text
currentmonthlytotal = Sheets("Project Leader Project Status").Cells(iCounter, 3).Text
total = Sheets("Project Leader Project Status").Cells(iCounter, 4).Text
balance = Sheets("Project Leader Project Status").Cells(iCounter, 5).Text
percentcomplete = Sheets("Project Leader Project Status").Cells(iCounter, 6).Text
popstart = Sheets("Project Leader Project Status").Cells(iCounter, 7).Text
popend = Sheets("Project Leader Project Status").Cells(iCounter, 8).Text
followonproject = Sheets("Project Leader Project Status").Cells(iCounter, 9).Text
projectleaderemail = Sheets("Project Leader Project Status").Cells(iCounter, 10).Text
reportperiodLength = Len(reportperiod)
slinLength = Len(slin)
budgetLength = Len(budget)
currentmonthlytotalLength = Len(currentmonthlytotal)
totalLength = Len(total)
balanceLength = Len(balance)
percentcompleteLength = Len(percentcomplete)
popstartLength = Len(popstart)
popendLength = Len(popend)
followonprojectLength = Len(followonproject)
projectleaderemailLength = Len(projectleaderemail)
If reportperiodLength > 9 Then
spaceString = ""
Else
spaceString = String(10 - reportperiodLength, " ")
End If
reportperiod = reportperiod + spaceString
If slinLength > 22 Then
spaceString = ""
Else
spaceString = String(23 - slinLength, " ")
End If
slin = slin + spaceString
If budgetLength > 9 Then
spaceString = ""
Else
spaceString = String(10 - budgetLength, " ")
End If
budget = budget + spaceString
If currentmonthlytotalLength > 8 Then
spaceString = ""
Else
spaceString = String(9 - currentmonthlytotalLength, " ")
End If
currentmonthlytotal = currentmonthlytotal + spaceString
If totalLength > 7 Then
spaceString = ""
Else
spaceString = String(8 - totalLength, " ")
End If
total = total + spaceString
If balanceLength > 8 Then
spaceString = ""
Else
spaceString = String(9 - balanceLength, " ")
End If
balance = balance + spaceString
If percentcompleteLength > 11 Then
spaceString = ""
Else
spaceString = String(12 - percentcompleteLength, " ")
End If
percentcomplete = percentcomplete + spaceString
If popstartLength > 10 Then
spaceString = ""
Else
spaceString = String(11 - popstartLength, " ")
End If
popstart = popstart + spaceString
If popendLength > 12 Then
spaceString = ""
Else
spaceString = String(13 - popendLength, " ")
End If
popend = popend + spaceString
If followonprojectLength > 10 Then
spaceString = ""
Else
spaceString = String(11 - followonprojectLength, " ")
End If
followonproject = followonproject + spaceString
If projectleaderemailLength > 35 Then
spaceString = ""
Else
spaceString = String(36 - projectleaderemailLength, " ")
End If
projectleaderemail = projectleaderemail + spaceString
.HTMLBody = .HTMLBody + slin + budget + currentmonthlytotal + total + balance + percentcomplete + popstart + popend + followonproject + projectleaderemail + "<br>"
iCounter = iCounter + 1
Loop
.HTMLBody = .HTMLBody + "</pre>"
.Send
End With
'Clean up the Outlook application.
Set olMailItm = Nothing
Set olApp = Nothing
End Sub
' This routine will send the Project Leader Project Status Sheet
'
Private Sub SendProjectLeaderProjectStatusToISOEmail(Email As String)
'Setting up the Excel variables.
Dim olApp As Object
Dim olMailItm As Object
Dim iCounter As Integer
Dim reportperiod As String
Dim slin As String
Dim budget As String
Dim currentmonthlytotal As String
Dim total As String
Dim balance As String
Dim percentcomplete As String
Dim popstart As String
Dim popend As String
Dim followonproject As String
Dim projectleaderemail As String
Dim reportperiodLength As String
Dim slinLength As String
Dim budgetLength As String
Dim currentmonthlytotalLength As String
Dim totalLength As String
Dim balanceLength As String
Dim percentcompleteLength As String
Dim popstartLength As String
Dim popendLength As String
Dim followonprojectLength As String
Dim projectleaderemailLength As String
Dim spaceString As String
'Create the Outlook application and the empty email.
Set olApp = CreateObject("Outlook.Application")
Set olMailItm = olApp.CreateItem(0)
iCounter = 4
'Select the ActiveCell on that worksheet
Set rng = ActiveCell
'Using the email, add multiple recipients, using a list of addresses in column A.
With olMailItm
'Do additional formatting on the BCC and Subject lines, add the body text from the spreadsheet, and send.
.Sender = Email
.To = Email
.Subject = "Project Leader Project Status" + Format(Now, " YYYY-MM-DD")
.HTMLBody = "<P STYLE='font-family:Courier New;font-size:8pt;color: rgb(0,0,0)'><br><pre>"
Do While Sheets("Project Leader Project Status").Cells(iCounter, 1).Text <> ""
reportperiod = Sheets("Project Leader Project Status").Cells(iCounter, 1).Text
slin = Sheets("Project Leader Project Status").Cells(iCounter, 1).Text
budget = Sheets("Project Leader Project Status").Cells(iCounter, 2).Text
currentmonthlytotal = Sheets("Project Leader Project Status").Cells(iCounter, 3).Text
total = Sheets("Project Leader Project Status").Cells(iCounter, 4).Text
balance = Sheets("Project Leader Project Status").Cells(iCounter, 5).Text
percentcomplete = Sheets("Project Leader Project Status").Cells(iCounter, 6).Text
popstart = Sheets("Project Leader Project Status").Cells(iCounter, 7).Text
popend = Sheets("Project Leader Project Status").Cells(iCounter, 8).Text
followonproject = Sheets("Project Leader Project Status").Cells(iCounter, 9).Text
projectleaderemail = Sheets("Project Leader Project Status").Cells(iCounter, 10).Text
reportperiodLength = Len(reportperiod)
slinLength = Len(slin)
budgetLength = Len(budget)
currentmonthlytotalLength = Len(currentmonthlytotal)
totalLength = Len(total)
balanceLength = Len(balance)
percentcompleteLength = Len(percentcomplete)
popstartLength = Len(popstart)
popendLength = Len(popend)
followonprojectLength = Len(followonproject)
projectleaderemailLength = Len(projectleaderemail)
If reportperiodLength > 9 Then
spaceString = ""
Else
spaceString = String(10 - reportperiodLength, " ")
End If
reportperiod = reportperiod + spaceString
If slinLength > 22 Then
spaceString = ""
Else
spaceString = String(23 - slinLength, " ")
End If
slin = slin + spaceString
If budgetLength > 9 Then
spaceString = ""
Else
spaceString = String(10 - budgetLength, " ")
End If
budget = budget + spaceString
If currentmonthlytotalLength > 8 Then
spaceString = ""
Else
spaceString = String(9 - currentmonthlytotalLength, " ")
End If
currentmonthlytotal = currentmonthlytotal + spaceString
If totalLength > 7 Then
spaceString = ""
Else
spaceString = String(8 - totalLength, " ")
End If
total = total + spaceString
If balanceLength > 8 Then
spaceString = ""
Else
spaceString = String(9 - balanceLength, " ")
End If
balance = balance + spaceString
If percentcompleteLength > 11 Then
spaceString = ""
Else
spaceString = String(12 - percentcompleteLength, " ")
End If
percentcomplete = percentcomplete + spaceString
If popstartLength > 10 Then
spaceString = ""
Else
spaceString = String(11 - popstartLength, " ")
End If
popstart = popstart + spaceString
If popendLength > 12 Then
spaceString = ""
Else
spaceString = String(13 - popendLength, " ")
End If
popend = popend + spaceString
If followonprojectLength > 10 Then
spaceString = ""
Else
spaceString = String(11 - followonprojectLength, " ")
End If
followonproject = followonproject + spaceString
If projectleaderemailLength > 35 Then
spaceString = ""
Else
spaceString = String(36 - projectleaderemailLength, " ")
End If
projectleaderemail = projectleaderemail + spaceString
.HTMLBody = .HTMLBody + slin + budget + currentmonthlytotal + total + balance + percentcomplete + popstart + popend + followonproject + projectleaderemail + "<br>"
iCounter = iCounter + 1
Loop
.HTMLBody = .HTMLBody + "</pre>"
.Send
End With
'Clean up the Outlook application.
Set olMailItm = Nothing
Set olApp = Nothing
End Sub