showboat098
New Member
- Joined
- Dec 3, 2012
- Messages
- 17
I receive the run-time error after my very last end sub. The code runs everything I want it just shows that error at the end. The final end sub uses the bb code to make it blue. Sorry for the long code. I'm running Windows 7 and Word 2010.
Hopefully I did that right.
Rich (BB code):
Public thisQuarter As String
Public thisYear As String
Dim j As Integer
Dim compDir As Object
Dim compDir2 As Object
Dim nameProd As String
Private Sub UserForm_Initialize()
askForQuarter:
'prompts for quarter, checks if user hit cancel then if 2 chars were entered
thisQuarter = InputBox("Please enter the current quarter", "Quarter", "(i.e. Q2)")
If thisQuarter = "False" Then
Exit Sub
End If
If Len(thisQuarter) < 2 Or Len(thisQuarter) > 2 Then
MsgBox "The format you used to enter the quarter is incorrect. Please enter the quarter in the format Q# (i.e. Q2)", , "Invalid Input"
GoTo askForQuarter
End If
askForYear:
'prompts for year, checks if user hit cancel then if 4 chars were entered
thisYear = InputBox("Please enter the current year", "Year", "(i.e. 2011)")
If thisYear = "False" Then
Exit Sub
End If
If Len(thisYear) < 4 Or Len(thisYear) > 4 Then
MsgBox "The format you used to enter the year is incorrect. Please enter the quarter in the format YYYY (i.e. YYYY)", , "Invalid Input"
GoTo askForYear
End If
Dim FromPath As String
Dim Tester As String
Dim Test2 As String
Dim ToPath As String
Dim ToPath2 As String
Dim fso As Object
Tester = "Z:\home\Marketing\common\BDS Associates\Consultant Database Group\D - Quarterly Files & Notes\" & thisYear & thisQuarter & "\Semi-Annual PDM Review\eVestment\Long Duration Team\"
Test2 = "Z:\home\Marketing\common\BDS Associates\Consultant Database Group\D - Quarterly Files & Notes\" & thisYear & thisQuarter & "\Semi-Annual PDM Review\Mercer\Long Duration\"
ToPath = "Z:\home\Marketing\common\BDS Associates\Consultant Database Group\D - Quarterly Files & Notes\" & thisYear & thisQuarter & "\Semi-Annual PDM Review\eVestment"
ToPath2 = "Z:\home\Marketing\common\BDS Associates\Consultant Database Group\D - Quarterly Files & Notes\" & thisYear & thisQuarter & "\Semi-Annual PDM Review\Mercer"
FromPath = "Z:\home\Marketing\common\BDS Associates\Consultant Database Group\D - Quarterly Files & Notes\Support"
Set fso = CreateObject("scripting.filesystemobject")
If fso.FolderExists(Tester) = False Then 'if topath doesn't exist then copy frompath to topath
fso.CopyFolder source:=FromPath, Destination:=ToPath
End If
If fso.FolderExists(Test2) = False Then
fso.CopyFolder source:=FromPath, Destination:=ToPath2
End If
'Call ShowDialog
'End Sub
'Sub ShowDialog()
Productform.Show
[color = blue]End Sub[/color]
Private Sub CommandButton1_Click()
Dim FromPath As String
Dim ToPath As String
Dim fso As Object
Dim i As Integer
Dim Home1 As String
Dim Home2 As String
'''Dim FileInFromFolder As Object
Dim fileObj As Object
'Dim compDir As Object
Dim FileComp As Object
Dim Str1 As String
'Dim compDir2 As Object
Dim fileComp2 As Object
'Dim nameProd As String
'Dim j As Integer
Home1 = "Z:\home\Marketing\common\BDS Associates\Consultant Database Group\D - Quarterly Files & Notes\" & thisYear & thisQuarter & "\Semi-Annual PDM Review\eVestment\"
Home2 = "Z:\home\Marketing\common\BDS Associates\Consultant Database Group\D - Quarterly Files & Notes\" & thisYear & thisQuarter & "\Semi-Annual PDM Review\Mercer\"
'Set FSO = CreateObject("scripting.filesystemobject")
If Me.CheckBox21.Value = True Then 'Sets all check boxes as true if "select all" is true. Select All is checkbox 21
CheckBox1.Value = True 'if a checkbox is added make sure to change the "select all" checkbox number and add the new checkbox to this list
CheckBox2.Value = True
CheckBox3.Value = True
CheckBox4.Value = True
CheckBox5.Value = True
CheckBox6.Value = True
CheckBox7.Value = True
CheckBox8.Value = True
CheckBox9.Value = True
CheckBox10.Value = True
CheckBox11.Value = True
CheckBox12.Value = True
CheckBox13.Value = True
CheckBox14.Value = True
CheckBox15.Value = True
CheckBox16.Value = True
CheckBox17.Value = True
CheckBox18.Value = True
CheckBox19.Value = True
CheckBox20.Value = True
End If
Set fso = CreateObject("Scripting.FileSystemObject")
Set compDir = fso.GetFolder("\\nasprodpmwin\marketing\common\BDS Associates\Consultant Database Group\D - Quarterly Files & Notes\" & thisYear & thisQuarter & "\Semi-Annual PDM Review\eVestment\")
Set compDir2 = fso.GetFolder("\\nasprodpmwin\marketing\common\BDS Associates\Consultant Database Group\D - Quarterly Files & Notes\" & thisYear & thisQuarter & "\Semi-Annual PDM Review\Mercer\")
Set FileComp = compDir.Files
Set fileComp2 = compDir2.Files
For j = 1 To 20
If Me.Controls("checkbox" & j).Value = True Then
nameProd = Me.Controls("checkbox" & j).Caption
For Each fileObj In FileComp
Str1 = Left(fileObj.Name, 3)
If Str1 = Left(nameProd, 3) Then
FromPath = fileObj
ToPath = Home1 & nameProd & "\" & fileObj.Name
fso.MoveFile source:=FromPath, Destination:=ToPath
End If
Next
For Each fileObj In fileComp2
Str1 = Left(fileObj.Name, 3)
If Str1 = Left(nameProd, 3) Then
FromPath = fileObj
ToPath = Home2 & nameProd & "\" & fileObj.Name
fso.MoveFile source:=FromPath, Destination:=ToPath
End If
Next
End If
Next j
Call Zip_All_Files_in_Folder
Unload Productform
End Sub
Sub NewZip(sPath)
'Create empty Zip File
'Changed by keepITcool Dec-12-2005
If Len(Dir(sPath)) > 0 Then Kill sPath
Open sPath For Output As #1
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
Close #1
End Sub
Sub Zip_All_Files_in_Folder()
Dim FileNameZip, FolderName
Dim strDate As String, DefPath As String
Dim oApp As Object
Dim fso As Object
Dim compDir As Object
Dim compDir2 As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set compDir = fso.GetFolder("\\nasprodpmwin\marketing\common\BDS Associates\Consultant Database Group\D - Quarterly Files & Notes\" & thisYear & thisQuarter & "\Semi-Annual PDM Review\eVestment\")
Set compDir2 = fso.GetFolder("\\nasprodpmwin\marketing\common\BDS Associates\Consultant Database Group\D - Quarterly Files & Notes\" & thisYear & thisQuarter & "\Semi-Annual PDM Review\Mercer\")
For j = 1 To 20
If Me.Controls("checkbox" & j).Value = True Then
nameProd = Me.Controls("checkbox" & j).Caption
DefPath = compDir & "\" & "Zipped Folders"
If Right(DefPath, 1) <> "\" Then
DefPath = DefPath & "\"
End If
FolderName = compDir & "\" & nameProd & "\" 'folder to be zipped
'strDate = Format(Now, " dd-mmm-yy h-mm-ss")
FileNameZip = compDir & "\" & nameProd & ".zip" 'destination of zipped folder
'Create empty Zip File
NewZip (FileNameZip) 'Call to sPath
Set oApp = CreateObject("Shell.Application")
'Copy the files to the compressed folder
oApp.Namespace(FileNameZip).CopyHere oApp.Namespace(FolderName).items
On Error Resume Next
Do Until oApp.Namespace(FileNameZip).items.Count = _
oApp.Namespace(FolderName).items.Count
Loop
On Error GoTo 0
End If
Next
For j = 1 To 20
If Me.Controls("checkbox" & j).Value = True Then
nameProd = Me.Controls("checkbox" & j).Caption
DefPath = compDir2 & "\" & "Zipped Folders" 'destination of zipped folder
If Right(DefPath, 1) <> "\" Then
DefPath = DefPath & "\"
End If
FolderName = compDir2 & "\" & nameProd & "\" 'folder to be zipped
'strDate = Format(Now, " dd-mmm-yy h-mm-ss")
FileNameZip = compDir2 & "\" & nameProd & ".zip"
'Create empty Zip File
NewZip (FileNameZip)
Set oApp = CreateObject("Shell.Application")
'Copy the files to the compressed folder
oApp.Namespace(FileNameZip).CopyHere oApp.Namespace(FolderName).items
'Keep script waiting until Compressing is done
On Error Resume Next
Do Until oApp.Namespace(FileNameZip).items.Count = _
oApp.Namespace(FolderName).items.Count
' Application.Wait (Now + TimeValue("0:00:01"))
Loop
On Error GoTo 0
End If
Next
Call Attach_and_Email
End Sub
Sub Attach_and_Email()
Dim sendTo As String
Dim typeSubject As String
Dim CCto As String
Dim sUser As String
Dim emailSign As String
Dim teamName As String
Dim bodySend As String
sUser = Environ("UserName")
Select Case sUser
Case "qucallan"
emailSign = "Consultant Database Group"
teamName = "ConsultantDatabaseGroup"
Case "tcramm"
emailSign = "Consultant Database Group"
teamName = "ConsultantDatabaseGroup"
Case "cdietrich"
emailSign = "Consultant Database Group"
teamName = "ConsultantDatabaseGroup"
End Select
Dim emailBody As String
Dim IsWeekend
Dim dateNew
Dim formattedDate
Dim sPath As String
Dim sPath2 As String
Dim Home1 As String
Dim Home2 As String
'If sendTo <> "compliancemarketingreview@pimco.com" Then
'
'For i = 0 To CountIt
'
'emailBody = emailBody & "
" & questionArray(i)
'
'Next i
'
'End If
Select Case Weekday(DateAdd("d", 10, Date))
Case vbSaturday
IsWeekend = 14
Case vbSunday
IsWeekend = 14
Case Else
IsWeekend = 14
End Select
dateNew = DateAdd("d", IsWeekend, Date)
formattedDate = Format(dateNew, ": mm/dd")
Home1 = "Z:\home\Marketing\common\BDS Associates\Consultant Database Group\D - Quarterly Files & Notes\" & thisYear & thisQuarter & "\Semi-Annual PDM Review\eVestment\"
Home2 = "Z:\home\Marketing\common\BDS Associates\Consultant Database Group\D - Quarterly Files & Notes\" & thisYear & thisQuarter & "\Semi-Annual PDM Review\Mercer\"
For j = 1 To 20
If Me.Controls("Checkbox" & j).Value = True Then
Select Case j
Case 1 'Absolute Return
sendTo = "Alts PDM"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 2 'Alternatives
sendTo = "Alts PDM"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 3 'Asset Allocation
sendTo = "Asset Alloc PDM"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 4 'Canadian
sendTo = "Patrice.Denis@pimco.com"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon Patrice"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 5 'Core
sendTo = "TR Message Committee"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 6 'Credit
sendTo = "Credit PDM Team PDM"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 7 'Dividend
sendTo = "Dividend Team PDM"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 8 'EM Equity
sendTo = "Equity PDM"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 9 'Emerging Markets
sendTo = "EM PDM Team"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 10 'ETF
sendTo = "ETF PDM Team"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 11 'Global
sendTo = "Global PDM Team"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 12 'Long Duration
sendTo = "LDI PDM Team"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 13 'Long - Short
sendTo = "Equity Long-Short PDM Team"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 14 'Mortgage
sendTo = "MBS/ABS PDM Team"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 15 'Municipal
sendTo = "Municipals PDM Team"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 16 'Pathfinder
sendTo = "Pathfinder PDM Team"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 17 'Real Return & Commodities
sendTo = "Real Return PDM Team"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 18 'Short Term
sendTo = "ShortTermPDMTeam"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 19 'StocksPLUS
sendTo = "StockPLUSPDMTeam"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
Case 20 'Tail Risk
sendTo = "trh_pdm"
typeSubject = "Product Review - Consultant Databases"
bodySend = "Good Afternoon" & " " & Me.Controls("checkbox" & j).Caption & " " & "Team,"
sPath = Home1 & Me.Controls("checkbox" & j).Caption & ".zip"
sPath2 = Home2 & Me.Controls("checkbox" & j).Caption & ".zip"
End Select
Dim DataObj As New MSForms.DataObject
Dim S As String
'Dim sPath As String
Dim sName As String
Dim CountIt
'The following is pulled from the BDS Toolbar and was left in to keep the integrity of the code intact.
'sName = ActiveDocument.Name
'compDir = ("\\nasprodpmwin\marketing\common\BDS Associates\Consultant Database Group\D - Quarterly Files & Notes\" & thisYear & thisQuarter & "\Semi-Annual PDM Review\Mercer\")
'
'For For j = 1 To 20
'
'
'Set FSO = CreateObject("Scripting.FileSystemObject")
'Set compDir = FSO.GetFolder(sPath & Me.Controls("checkbox" & j).Caption & ".zip"
'
'Set FileComp = compDir.Files
'
'For Each fileObj In FileComp
'
' Str1 = fileObj.Name
'
'Next
'
'If Len(Selection) > 1 Or sendTo <> "compliancemarketingreview@pimco.com" Then
'
'CountIt = 0
'Selection.Copy
'
''Highlight questions that are sent out
'Selection.Range.HighlightColorIndex = wdRed
'
'
'
'DataObj.GetFromClipboard
'S = DataObj.GetText
'
'ReDim questionArray(0 To UBound(Split(S, vbCr))) ' As Integer
'For i = 0 To UBound(Split(S, vbCr))
'
' questionArray(i) = Split(S, vbCr)(i)
' CountIt = CountIt + 1
'
'Next
'
'CountIt = CountIt - 1
'
Dim OutApp As Object
Dim OutMail As Object
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
On Error GoTo cleanup
'nameProd = Me.Controls("checkbox" & j).Caption
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.to = sendTo & ";" & CCto
.CC = teamName & "@pimco.com"
.Subject = "Due" & formattedDate & " - " & typeSubject & " - Request for Assistance"
.HTMLBody = bodySend & "
" & "
" & _
"As part of the bi-annual Product Management - Consultant Database Review initiative, we have attached your team's " & thisQuarter & thisYear & " product profiles from the eVestment Alliance and Mercer GIMD consultant databases for review. It's important to have final signoff from Product Managers for each product. Please make comments to the PDF documents electronically or hand write and email your changes to us. If you have extensive changes to the narratives, we will be happy to provide the narratives in word for ease of making edits. " & "" & "Please respond with your feedback or edits by no later than" & _
" " & WeekdayName(Weekday(dateNew)) & ", " & MonthName(Month(dateNew)) & " " & Day(dateNew) & "." & "" & "
" & "
" & "" & "" & "Questions/Assistance" & "" & "" & "
" & "We have created an FAQ document to help answer some of your past questions," & _
"which you can access by clicking " & "" & "INSERT LINK TO FAQ HERE." & "" & " The FAQ contains useful information regarding answer selections, sources of information, limitations and idiosyncrasies within eVestment and Mercer. If you have any questions, please do not hesitate to contact our group at " & "" & "" & "CDG@pimco.com" & "." & "" & "" & "
" & "
" & "We appreciate your team's time and involvement in this initiative and look forward to working with you." & "
" & "
" & "Best Regards," & "
" & "
" & _
emailSign & "
" & "
" & _
"" & emailBody & ""
.Attachments.Add (sPath)
.Attachments.Add (sPath2)
'.Attachments.Add (sPath & "\" & sName)
.Display 'Or use Send
On Error GoTo 0
Set OutMail = Nothing
End With
Dim objFSO As Object
Dim objfolder As String
Dim objfolder2 As String
'objfolder = "Z:\home\Marketing\common\BDS Associates\Consultant Database Group\D - Quarterly Files & Notes\2012Q4\Semi-Annual PDM Review\Mercer\Long-Short"
objfolder = Home1 & Me.Controls("CheckBox" & j).Caption
objfolder2 = Home2 & Me.Controls("CheckBox" & j).Caption
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.deletefolder objfolder
objFSO.deletefolder objfolder2
'objFSO.deletefolder objfolder2
End If
Next j
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
'Unload Productform
'Call Delete
End Sub
Hopefully I did that right.