Wildcard date format not resolved in Word - date

In this loop (iii = 12 to 1 step -1), the .text wildcard doesn't find any dates at all:
With Selection.FInd
.Forward = True
.Wrap = WdFindStop
.text= "([0-9]{1,2}] " & Mon_th(iii) & ([0-9]{4}])"
.Execute
End With
But in this loop, it does:
With ActiveDocument.Content
With.Find
.Forward = True
.Wrap = WdFindStop
.text= "([0-9]{1,2}] " & Mon_th(iii) & ([0-9]{4}])"
End With
I think I need to use the first version because I want to insert a comment every time a date is found, but can't figure out why it works with one but not the other.
All help appreciated, thanks.
Also, why does .text have an initial cap when I input it but changes to lower case immediately after?

You can, of course, do this without that loop. For example:
.Text = "<[0-9]{1,2} [JFMASOND][abceghilmnoprstuvy]{2,8} [12][0-9]{3}>"
or:
.Text = "<[0-9]{1,2} [JFMASOND][abceglnoprtuvy]{2} [12][0-9]{3}>"
If you need different comments, that can be achieved via a Select Case statement in the loop you'll already need for adding those. Thus:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "<[0-9]{1,2} [JFMASOND][abceglnoprtuvy]{2} [12][0-9]{3}>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
Do While .Find.Found
Select Case Split(.Text, " ")(1)
Case "Jan": .Comments.Add .Duplicate, "Comment for Jan"
Case "Feb": .Comments.Add .Duplicate, "Comment for Feb"
Case "Mar": .Comments.Add .Duplicate, "Comment for Mar"
Case "Apr": .Comments.Add .Duplicate, "Comment for Apr"
Case "May": .Comments.Add .Duplicate, "Comment for May"
Case "Jun": .Comments.Add .Duplicate, "Comment for Jun"
Case "Jul": .Comments.Add .Duplicate, "Comment for Jul"
Case "Aug": .Comments.Add .Duplicate, "Comment for Aug"
Case "Sep": .Comments.Add .Duplicate, "Comment for Sep"
Case "Oct": .Comments.Add .Duplicate, "Comment for Oct"
Case "Nov": .Comments.Add .Duplicate, "Comment for Nov"
Case "Dec": .Comments.Add .Duplicate, "Comment for Dec"
End Select
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
Application.ScreenUpdating = True
End Sub

Related

vbscript check if email is sent

I have created a script to send a weekly report but I don't know how to implement the status message if the email is successfully sent. Currently I just have a message which shows up on confirm to send the message, but that does not really check if the email is sent.
This is my script:
Dim fso, path, file, recentDate, recentFile, ToAddress, FromAddress, MessageSubject, MyTime, MessageBody, MessageAttachment, ol, ns, newMail
Set fso = CreateObject("Scripting.FileSystemObject")
Set recentFile = Nothing
For Each file in fso.GetFolder("C:\REPORTData\temp").Files
If (recentFile is Nothing) Then
If UCase(fso.GetExtensionName(file.name)) <> "PDF" Then
Set recentFile = file
End If
ElseIf (file.DateLastModified > recentFile.DateLastModified) Then
If UCase(fso.GetExtensionName(file.name)) <> "PDF" Then
Set recentFile = file
End If
End If
Next
ToAddress = "randomemail#randomemail.com"
MessageSubject = "Emailing: "+recentFile.Name
MessageBody = "Your message is ready to be sent with the following file or link attachments: "+recentFile.Name
MessageAttachment = "C:\REPORTData\temp\"+recentFile.Name
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody
newMail.RecipIents.Add(ToAddress)
newMail.Attachments.Add(MessageAttachment)
CurrentWeek = Right(recentFile.Name, 2)
result = MsgBox ("Send REPORT for week: "+CurrentWeek, vbYesNo + vbQuestion, "REPORT Sender v.0.1")
Select Case result
Case vbYes
newMail.Send
Set shell = CreateObject("Wscript.Shell")
shell.Popup "Your REPORT for week "+CurrentWeek+" has been sent", 2, "SUCCESS"
Case vbNo
End Select
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "dcandy#gmail.com"
emailObj.To = "dcandy#gmail.com"
emailObj.Subject = "Test CDO"
emailObj.TextBody = "Test CDO"
emailObj.AddAttachment "c:\windows\win.ini"
Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
emailConfig.Fields.Update
emailObj.Send
If err.number = 0 then
Msgbox "Done"
Else
Msgbox err.number
End if
is how.

Vbs Multiple Line Email

I am using a vbs file to send emails but it sends it in one line only. I want it to be multiple lines with & vbCRLF but it is not working for me.
Please help me with vbs emails with multiple line text.
My code :
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "dc#gail.com"
emailObj.To = "dc#gail.com"
emailObj.Subject = "Test CDO"
emailObj.TextBody = "Test CDO" & vbCRLF & "Test CDO line 2"
Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "YourUserName"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Password1"
emailConfig.Fields.Update
emailObj.Send
If err.number = 0 then Msgbox "Done"
Here's how I did it, just using ".HTMLBody" to be able to add formatting. Works fine using outlook.
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
with objMail
.Display 'To display message
.To = "test#test.com"
.cc = "test#tested.com"
.Subject = "FYI"
.HTMLBody = "<HTML><BODY><p>Dear Team,</p><P> Please be informed, </p><P> Regards, </p><P><B> My Name </B><br><big><i>My Company</i> </big>(of awesomeness) </br></p></BODY></HTML>"
end with

Form Load/Unload Event Not Triggered After Importing Form in Access 2007

So I just manually split a database following the steps found Here. For some reason the load event is not triggered on one form and on another the unload event is not triggered (but in each case, the opposite one does work). The second form (Unload not working) also refuses to go into design mode until I close it manually and then open it into design mode. I have confirmed that the open and close events are linked properly to their corresponding VBA code so I know that isn't it.
Any help with resolving this issue would be appreciated.
Edit-
Here is the code for the Load:
Private Sub Form_Load()
Dim scr As ScriptControl
Dim SQL As String
CheckConnection
Set scr = New ScriptControl
SQL = "UPDATE [Part Number] SET [Part Number].[Select] = False WHERE ((([Part Number].[Select])=True));"
CurrentDb.Execute SQL
scr.Language = "VBScript"
scr.AddCode "Sub T :Dim ChangeReg: Set ChangeReg = CreateObject(""WScript.Shell""):ChangeReg.regwrite " & _
"""HKCU\Software\Microsoft\Office\12.0\Access\Security\VBAWarnings"", ""1"", ""REG_DWORD"" : " & _
"Set ChangeReg = CreateObject(""WScript.Shell""):ChangeReg.regwrite " & _
"""HKCU\Software\Microsoft\Office\12.0\Excel\Security\VBAWarnings"", ""1"", ""REG_DWORD"": end sub"
scr.Run "T"
Locked = False
CancelBupdate = False
LockOff
USRID = Environ("Username")
TTTCount = 0
Started = True
SourceSelect.Value = 1
DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide
DoCmd.ShowToolbar "Ribbon", acToolbarNo
ChgFrmOpen = False
Me.LocationSelect.Visible = False
Me.ClrSupLoc.Visible = False
Me.Label20.Visible = False
PSOn = True
Me.RepSelect.Value = ""
Me.SupplierSelect.Value = ""
Me.SupNumSelect.Value = ""
Me.LocationSelect.Value = ""
Me.Base5Select.Value = ""
Me.FullNbrSelect.Value = ""
Me.Label104.Caption = "Last Updated On: " & DLookup("[Last Updated]", "[Last Updated]")
ChangeCount = 0
CT = ""
CPP = ""
PGNP = ""
UpdateSub '****
InfoGet
RunFilter
Cascade
Me.Requery
Select Case USRID
Case "vn034153"
UsrInfoSt = "Logged in as User"
Case "vn043156"
UsrInfoSt = "Logged in as User"
Blah
Case "vn034157"
UsrInfoSt = "Logged in as Admin"
Me.UpdateButton.Visible = True
Case "vn034160"
UsrInfoSt = "Logged in as User"
Case "vn028040"
UsrInfoSt = "Logged in as User"
Case "vn028033"
UsrInfoSt = "Logged in as Admin"
Me.UpdateButton.Visible = True
Case "vn034931"
UsrInfoSt = "Logged in as User"
Case Else
UsrInfoSt = "Logged in as User"
End Select
Me.UsrInfo.Caption = UsrInfoSt
Application.SetOption "Confirm Action Queries", 0
Application.SetOption "Confirm Document Deletions", 0
Application.SetOption "Confirm Record Changes", 0
DoCmd.SetWarnings False
Application.SetOption "Auto compact", True
End Sub
And here is the code for the unload (using a cmd button and neither sub runs):
Private Sub OpenDatabase_Click()
DoCmd.OpenForm "2BHPartsDatabaseX"
DoCmd.Close acForm, Me.Name
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim TDF As TableDef
Dim QDF As QueryDef
Dim DBS As Database
Set DBS = CurrentDb()
Me.ReportForm.SourceObject = ""
For Each QDF In DBS.QueryDefs
If QDF.Name = "TempQRYX" Or QDF.Name = "DistinctPGNQry" Then
DBS.QueryDefs.Delete QDF.Name
End If
Next
For Each TDF In DBS.TableDefs
If TDF.Name = "ProjectTable" Then
DBS.TableDefs.Delete TDF.Name
Exit For
End If
Next
Application.SetOption "Confirm Action Queries", 1
Application.SetOption "Confirm Document Deletions", 1
Application.SetOption "Confirm Record Changes", 1
DoCmd.SetWarnings True
End Sub
I would comment (rem) out all the code in the Form_Load Event, and put a breakpoint on the
Sub procedure, then open the form to see if the event fires. After I see it fire,
I would begin to "un-rem" each line until the code line affecting the load event
is found.
I would do the same with the "Unload" issue.

Pydev Program Continually Terminating

I am fairly new programmer, currently I have been assigned a project to create a looping calculator that even after you use one of the calculator functions it will keep going until you make a selection provided. My problem with my calculator currently is that there is an incessant termination whenever I try to test my function on Pydev. I already fixed the first problem where Pydev read one of my variables (choice) as unused so I used the "ctrl + 1" trick and that got rid of the unused variable warning. Any tips on how I might be able to run this program and have it continually loop?
def main():
loop=1
choice=0 # #UnusedVariable
while loop == 1:
print("Welcome to Calculator Function!")
print("Your options are:")
print(" ")
print("1/) Addition")
print("2/) Subtraction")
print("3/) Multiplication")
print("4/) Division")
print("5/) Quit CalculatorFunction.py")
print(" ")
choice = int(raw_input("Choose your option: ").strip())
if choice == 1:
add1 = input("Add what: ")
add2 = input("To what: ")
print add1, "+", add2, "=", add1+add2
elif choice == 2:
sub2 = input("Subtract what: ")
sub1 = input("From what: ")
print sub1, "-", sub2, "=", sub1-sub2
elif choice == 3:
mult1 = input("Multiply what: ")
mult2 = input("To what: ")
print mult1, "*", mult2, "=", mult1*mult2
elif choice == 4:
div2= input("Divide what: ")
div1= input("From what: ")
print div1, "/", div2, "=", div1/div2
elif choice == 5:
loop = 0
print"Thank you for using CalculatorFunction.py have a good day!"
else:
print"No selection made, please try again."
if __name__ == '__main__':
main()
Your if - else block is outside the while loop, that is why it doesn't work. Here's the properly indented code:
def main():
loop=1
choice=0 # #UnusedVariable
while loop == 1:
print("Welcome to Calculator Function!")
print("Your options are:")
print(" ")
print("1/) Addition")
print("2/) Subtraction")
print("3/) Multiplication")
print("4/) Division")
print("5/) Quit CalculatorFunction.py")
print(" ")
choice = int(raw_input("Choose your option: ").strip())
if choice == 1:
add1 = input("Add what: ")
add2 = input("To what: ")
print add1, "+", add2, "=", add1+add2
elif choice == 2:
sub2 = input("Subtract what: ")
sub1 = input("From what: ")
print sub1, "-", sub2, "=", sub1-sub2
elif choice == 3:
mult1 = input("Multiply what: ")
mult2 = input("To what: ")
print mult1, "*", mult2, "=", mult1*mult2
elif choice == 4:
div2= input("Divide what: ")
div1= input("From what: ")
print div1, "/", div2, "=", div1/div2
elif choice == 5:
loop = 0
print"Thank you for using CalculatorFunction.py have a good day!"
else:
print"No selection made, please try again."
if __name__ == '__main__':
main()
This worked well on pydev.
Thanks to your tips on "indentation" and a couple of other things I finally figured out the program works thank you all for your input. What I did to fix my immediate termination was fix the indentation. Then to make it so the program continually loops if a selection isn't made I added the continue, in essence the only way to terminate the program is to select the option quit which is listed as "5".
def main()
loop=1
choice=0 # #UnusedVariable
while loop == 1:
print(" ")
print("Welcome to Calculator Function!")
print("Your options are:")
print(" ")
print("1) Addition")
print("2) Subtraction")
print("3) Multiplication")
print("4) Division")
print("5) Quit CalculatorFunction.py")
print(" ")
choice = int(raw_input("Choose your option: ").strip())
if choice == 1:
add1 = int(raw_input("Add what: "))
add2 = int(raw_input("To what: "))
print add1, "+", add2, "=", add1+add2
elif choice == 2:
sub2 = int(raw_input("Subtract what: "))
sub1 = int(raw_input("From what: "))
print sub1, "-", sub2, "=", sub1-sub2
elif choice == 3:
mult1 = int(raw_input("Multiply what: "))
mult2 = int(raw_input("To what: "))
print mult1, "*", mult2, "=", mult1*mult2
elif choice == 4:
div2= int(raw_input("Divide what: "))
div1= int(raw_input("From what: "))
print div1, "/", div2, "=", div1/div2
elif choice == 5:
loop = 0 #Ends the program
print"Thank you for using CalculatorFunction.py have a good day!"
else:
print"No selection made, please try again."
continue #loops the program
if name == 'main':
main()

Sending email with multiple attachments vb6

Can someone help me.How to send an email with multiples attachments.
I am using cdo and SMTP Send Mail for VB6. Everything works great except I am only able to send one attachment at a time.
here's the code
Public Function SendMail(sTo As String, sSubject As String, sFrom As String, _
sBody As String, sSmtpServer As String, iSmtpPort As Integer, _
sSmtpUser As String, sSmtpPword As String, _
sFilePath As String, bSmtpSSL As Boolean) As String
On Error GoTo SendMail_Error:
Dim lobj_cdomsg As CDO.Message
Set lobj_cdomsg = New CDO.Message
lobj_cdomsg.Configuration.Fields(cdoSMTPServer) = sSmtpServer
lobj_cdomsg.Configuration.Fields(cdoSMTPServerPort) = iSmtpPort
lobj_cdomsg.Configuration.Fields(cdoSMTPUseSSL) = bSmtpSSL
lobj_cdomsg.Configuration.Fields(cdoSMTPAuthenticate) = cdoBasic
lobj_cdomsg.Configuration.Fields(cdoSendUserName) = sSmtpUser
lobj_cdomsg.Configuration.Fields(cdoSendPassword) = sSmtpPword
lobj_cdomsg.Configuration.Fields(cdoSMTPConnectionTimeout) = 30
lobj_cdomsg.Configuration.Fields(cdoSendUsingMethod) = cdoSendUsingPort
lobj_cdomsg.Configuration.Fields.Update
lobj_cdomsg.To = sTo
lobj_cdomsg.From = sFrom
lobj_cdomsg.Subject = sSubject
lobj_cdomsg.TextBody = sBody
If Trim$(sFilePath) <> vbNullString Then
lobj_cdomsg.AddAttachment (sFilePath)
End If
lobj_cdomsg.Send
Set lobj_cdomsg = Nothing
SendMail = "ok"
Exit Function
SendMail_Error:
SendMail = Err.Description
End Function
Private Sub cmdSend_Click()
Dim retVal As String
Dim objControl As Control
For Each objControl In Me.Controls
If TypeOf objControl Is TextBox Then
If Trim$(objControl.Text) = vbNullString And LCase$(objControl.Name) <> "txtAttach" Then
Label2.Caption = "Error: All fields are required!"
Exit Sub
End If
End If
Next
Frame1.Enabled = False
Frame2.Enabled = False
cmdSend.Enabled = False
Label2.Caption = "Sending..."
retVal = SendMail(Trim$(txtTo.Text), _
Trim$(txtSubject.Text), _
Trim$(txtFromName.Text) & "<" & Trim$(txtFromEmail.Text) & ">", _
Trim$(txtMsg.Text), _
Trim$(txtServer.Text), _
CInt(Trim$(txtPort.Text)), _
Trim$(txtUsername.Text), _
Trim$(txtPassword.Text), _
Trim$(txtAttach.Text), _
CBool(chkSSL.Value))
Frame1.Enabled = True
Frame2.Enabled = True
cmdSend.Enabled = True
Label2.Caption = IIf(retVal = "ok", "Message sent!", retVal)
End Sub
Private Sub cmdBrowse_Click()
Dim sFilenames() As String
Dim i As Integer
On Local Error GoTo Err_Cancel
With cmDialog
.FileName = ""
.CancelError = True
.Filter = "All Files (*.*)|*.*|HTML Files (*.htm;*.html;*.shtml)|*.htm;*.html;*.shtml|Images (*.bmp;*.jpg;*.gif)|*.bmp;*.jpg;*.gif"
.FilterIndex = 1
.DialogTitle = "Select File Attachment(s)"
.MaxFileSize = &H7FFF
.Flags = &H4 Or &H800 Or &H40000 Or &H200 Or &H80000
.ShowOpen
' get the selected name(s)
sFilenames = Split(.FileName, vbNullChar)
End With
If UBound(sFilenames) = 0 Then
If txtAttach.Text = "" Then
txtAttach.Text = sFilenames(0)
Else
txtAttach.Text = txtAttach.Text & ";" & sFilenames(0)
End If
ElseIf UBound(sFilenames) > 0 Then
If Right$(sFilenames(0), 1) <> "\" Then sFilenames(0) = sFilenames(0) & "\"
For i = 1 To UBound(sFilenames)
If txtAttach.Text = "" Then
txtAttach.Text = sFilenames(0) & sFilenames(i)
Else
txtAttach.Text = txtAttach.Text & ";" & sFilenames(0) & sFilenames(i)
End If
Next
Else
Exit Sub
End If
Err_Cancel:
End Sub
You are only passing in one file. Try passing in an array of files and loop through the array. Or, since it looks like its semicolon delimiting the list of files selected, try to just split the list...
For Each s As String in sFilePath.Split(";"c)
lobj_cdomsg.AddAttachemt(s)
Next
I have no idea how to run a vb 6 app anymore, but if this helps, please mark it so.