Hey Everyone,
I'm brand new to VBA, and I think I've exhausted my efforts in trying to figure out my problem. Our VBA expert left the company, and I was tasked with optimizing a tool that he created which we use to send email correspondences to candidates. The code works as is, but my manager wants specific documents to attach to their email depending on the candidate's role, location, and whether or not they're flying to our location. I refrained from adding the whole code since it's about 6 pages or so. Any suggestions are greatly appreciated, but I am 100% stuck right now. Keep in mind that since this tool is actually used for multiple purposes, not just for populating emails, I cannot shift around columns, rows, etc. It has to stay as is for other reporting.
'=== Create Email From Reference Files and Properties Above ===
Dim newDoc As Object
Call wdApp.Run("Replace", strCanFirstName, strCanLastName, strCanPhone, strCanEmail, strCanPosition, strIntDate, strIntTime, strIntLocation, strIntAddress, strRecName, strRecPhone, strRecEmail, strHotelName, strHotelAddress, strCarlsonTravel, lngRecordRow)
Call wdApp.Run("CreateEmail", strCanEmail, strAttachment1, lngRecordRow)
newDoc.Close SaveChanges:=wddonotsavechanges
'=============================================================
Really hope that's making sense, but that is the code currently wich works fine. So before the line third call, I need something along the lines of...
If UCase(strCanPosition) = "Finance" And UCase(strIntCity) = "Richmond" And UCase(bAirTravel = True) Then
Call wdApp.Run("CreateEmail", strCanEamil, strAttachment1, strAttachment2, lngRecordRow)
' That would be the first case, but it would then need to cycle others, and if none of the cases were true, it would use the statement that creates an email with just strAttachment1.
I feel like this is all convoluted, but if you need more clarity or insight let me know. Again, a huge thanks to any suggestions or insights as to what I could be doing wrong.
I'm brand new to VBA, and I think I've exhausted my efforts in trying to figure out my problem. Our VBA expert left the company, and I was tasked with optimizing a tool that he created which we use to send email correspondences to candidates. The code works as is, but my manager wants specific documents to attach to their email depending on the candidate's role, location, and whether or not they're flying to our location. I refrained from adding the whole code since it's about 6 pages or so. Any suggestions are greatly appreciated, but I am 100% stuck right now. Keep in mind that since this tool is actually used for multiple purposes, not just for populating emails, I cannot shift around columns, rows, etc. It has to stay as is for other reporting.
'=== Create Email From Reference Files and Properties Above ===
Dim newDoc As Object
Set newDoc = wdApp.Documents.Add(strTemplateFile)
Call wdApp.Run("Replace", strCanFirstName, strCanLastName, strCanPhone, strCanEmail, strCanPosition, strIntDate, strIntTime, strIntLocation, strIntAddress, strRecName, strRecPhone, strRecEmail, strHotelName, strHotelAddress, strCarlsonTravel, lngRecordRow)
Call wdApp.Run("DeleteParagraphs", bReception, bHotel, bCarlsonTravel, lngRecordRow)
Call wdApp.Run("CreateEmail", strCanEmail, strAttachment1, lngRecordRow)
newDoc.Close SaveChanges:=wddonotsavechanges
'=============================================================
Really hope that's making sense, but that is the code currently wich works fine. So before the line third call, I need something along the lines of...
If UCase(strCanPosition) = "Finance" And UCase(strIntCity) = "Richmond" And UCase(bAirTravel = True) Then
Call wdApp.Run("CreateEmail", strCanEamil, strAttachment1, strAttachment2, lngRecordRow)
' That would be the first case, but it would then need to cycle others, and if none of the cases were true, it would use the statement that creates an email with just strAttachment1.
I feel like this is all convoluted, but if you need more clarity or insight let me know. Again, a huge thanks to any suggestions or insights as to what I could be doing wrong.