.Range(.cells(x,y)).select not working & hyperlink help

john316swan

Board Regular
Joined
Oct 13, 2016
Messages
66
Office Version
  1. 2019
Platform
  1. Windows
I am having trouble with 2 issues (don't know if 2nd one was fixed because I haven't been able to get past runtime error '1004': Application-defined or object-defined error

Here is my entire code:

Code:
Sub loanDisbursementNotification()
Dim lr As Long, x As Long, y As Long
Dim strHeader As String, strbody As String, loanBody As String
Dim tugFolder As String, spsFolder As String, studFolder As String, archiveFolder As String, missingFolder As String
Dim acadYear As String, SigString As String, signature As String, prog As String
Dim FSO As Scripting.FileSystemObject
Dim OL As Outlook.Application
Dim disbNotif As Outlook.MailItem


With Application
    .EnableEvents = False
    .ScreenUpdating = False
End With




lr = Sheets("Notification").Cells(Rows.Count, 1).End(xlUp).Row
tugFolder = "M:\Financial Aid\ELECTRONIC FILES\TRADITIONAL UNDERGRAD\"
spsFolder = "M:\Financial Aid\ELECTRONIC FILES\SPS\"
archiveFolder = "M:\Financial Aid\ELECTRONIC FILES\ARCHIVE FOLDER\"
missingFolder = "M:\Financial Aid\Loan Disbursement Notifications\Missing Folders\"
acadYear = "\2018-2019\"
SigString = Environ("appdata") & "\Microsoft\Signatures\No Logo.htm"
signature = GetSignature(SigString)
Set FSO = New Scripting.FileSystemObject


'We're going to loop through all students and send them an email
For x = 2 To 2 'lr


    strHeader = "Dear " & Cells(x, 4) & ",<br><br>" _
              & "<b><i><u>WHAT IS THIS?</b></i></u> -- This is a federally required NOTIFICATION ONLY that the Financial Aid " _
              & "Office has received 1 or more disbursements of your Federal Student Loan(s).<br><br>" _
              & "<b><i><u>WHAT DO YOU NEED TO DO?</b></i></u> -- Usually...nothing! You have already told us at one time that " _
              & "you wanted these loans. We are simply required to disclose to you that they came in.<br><br>" _
              & "<b><i><u>WHAT IF I DON'T WANT THEM ANYMORE?</b></i></u> -- If you wish to reduce or cancel all or part of any " _
              & "disbursement, you have 14 calendar days from the date of this notification (" & Date & ") to inform your " _
              & "Financial Aid Counselor, " & Cells(x, 8) & ", in writing (email is prefered) to request a cancellation or " _
              & "reduction of your Federal Student Loan.<br><br>" _
              & "This notice refers to the following loan disbursement(s) <u>credited to your student account on " & Cells(x, 7) & "</u>:<br><br>" _
              
              If Cells(x, 5) > 0 Then
                loanBody = "<b>Subsidized loan(s)</b> in the amount of: " & Format(Cells(x, 5), "$#,###") & "<br>"
              End If
              If Cells(x, 6) > 0 Then
                loanBody = loanBody & "<b>Unsubsidized loan(s)</b> in the amount of: " & Format(Cells(x, 6), "$#,###") & "<br>"
              End If
              
    strbody = loanBody & "<br>If you have any question regarding this notification or any other aspect of your financial aid, " _
              & "please contact <b>" & Cells(x, 8) & "</b>.<br>" & signature & "<br><br><b><i>PS - Don't forget...incurring " _
              & "a loan obligation is a serious responsibility - these are funds that you will have to pay back!</b></i>"
              
    'This is where you left off, need to use FSO to determine if active folder exists...if not, then archive
    If Cells(x, 10) = "TUG" Then
        studFolder = tugFolder & Left(Cells(x, 3), 1) & "\" & Cells(x, 3) & ", " & Cells(x, 4) & " " & Right(Cells(x, 2), 5) & acadYear
        If Not FSO.FolderExists(studFolder) Then
            studFolder = archiveFolder & Left(Cells(x, 3), 1) & "\" & Cells(x, 3) & ", " & Cells(x, 4) & " " & Right(Cells(x, 2), 5) & acadYear
        End If
    ElseIf Cells(x, 10) = "SPS" Then
        studFolder = spsFolder & Left(Cells(x, 3), 1) & "\" & Cells(x, 3) & ", " & Cells(x, 4) & " " & Right(Cells(x, 2), 5) & acadYear
        If Not FSO.FolderExists(studFolder) Then
            studFolder = archiveFolder & Left(Cells(x, 3), 1) & "\" & Cells(x, 3) & ", " & Cells(x, 4) & " " & Right(Cells(x, 2), 5) & acadYear
        End If
    End If
    
    'If a folder doesn't exist then we will file in a "To be filed" folder
    If Not FSO.FolderExists(studFolder) Then
        studFolder = missingFolder
    End If
    
    Set OL = CreateObject("Outlook.Application")
    Set disbNotif = OL.CreateItem(0)


    With disbNotif
        .To = Cells(x, 9)
        .Subject = Cells(x, 3) & ", " & Cells(x, 4) & " " & Right(Cells(x, 2), 5) & " - Loan Disbursement Notification"
        .HTMLBody = strHeader & strbody
        .SaveAs studFolder & Cells(x, 3) & ", " & Cells(x, 4) & " " & Right(Cells(x, 2), 5) & " - Loan Disbursement Notification " & Format(Date, "mm-dd-yyyy") & ".msg", olMSG
        .Display
        '.Send Will remove display and use send when finished debugging
    End With
    
    Cells(x, 11) = studFolder
        With ActiveSheet
            .Range(.Cells(x, 11)).Select
            .Hyperlinks.Add Anchor:=Selection, _
            Address:=studFolder
        End With
        
    Cells(x, 12) = "Sent on " & Format(Date, "m/d/yyyy")


Next x


With Application
    .EnableEvents = True
    .ScreenUpdating = True
End With




End Sub

Function GetSignature(ByVal sFile As String) As String
    Dim FSO As Object
    Dim ts As Object
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set ts = FSO.GetFile(sFile).OpenAsTextStream(1, -2)
    GetSignature = ts.ReadAll
    ts.Close
End Function

Here is the code I am having trouble with:

Code:
    Cells(x, 11) = studFolder
        With ActiveSheet
            .Range(.Cells(x, 11)).Select
            .Hyperlinks.Add Anchor:=Selection, _
            Address:=studFolder
        End With
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Change this
.Range(.Cells(x, 11)).Select

By
.Cells(x, 11).Select
 
Upvote 0
Solution

Forum statistics

Threads
1,214,912
Messages
6,122,200
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top