Getting open Outlook 2016 Application OLE Object in Win 10

Started by notds, August 22, 2018, 03:01:44 PM

Previous topic - Next topic

notds

Previous examples stopped working. I can close outlook and create object. But I also can't seem to close the mail object and send a second email after I've sent one already.

This used to work famously. Drat. Can anyone provide up to date working code examples?

notds

Here's the code I'm trying to get to work with Windows 10 and Outlook 2016

Code  winbatch Select
recip="me@someplace.org"
				AttachmentPath=""
				objOutlook = ObjectCreate("Outlook.Application")


#DefineSubroutine MyDialogCallbackProc(MyDialog_Handle,MyDialog_Event,MyDialog_Name,MyDialog_EventInfo,MyDialog_ChangeInfo)
	switch MyDialog_Event                                    ; Switch based on Dialog Message type
		case @deInit                                          ; Standard Initialization message
;			DialogProcOptions(MyDialog_Handle,@deTimer,1000)
			DialogProcOptions(MyDialog_Handle,@dePbPush,@TRUE)
			DialogProcOptions(MyDialog_Handle,@deCbCheck,@TRUE)
			DialogProcOptions(MyDialog_Handle,@deEdText,@TRUE)
			DialogProcOptions(MyDialog_Handle,@deSpChange,@TRUE)
			return(@retDefault)

		case @dePbPush
			if MyDialog_Name == "PushButton_OK"                ; Create Tickets

				startnum = DialogControlGet( MyDialog_Handle, "Spinner_1", 8 )
				endnum = DialogControlGet( MyDialog_Handle, "Spinner_2", 8 )
				inserttotitle = DialogControlGet( MyDialog_Handle, "CheckBox_1", 1 )
				inserttomsg = DialogControlGet( MyDialog_Handle, "CheckBox_2", 1 )	
				title_A = DialogControlGet( MyDialog_Handle, "EditBox_titlepa", 3 )
				title_B = DialogControlGet( MyDialog_Handle, "EditBox_titlepb", 3 )
				msg_A = DialogControlGet( MyDialog_Handle, "MultiLineBox_mbpa", 3 )
				msg_B = DialogControlGet( MyDialog_Handle, "MultiLineBox_mbpb", 3 )

				

				For x = startnum to endnum




				If inserttotitle && inserttomsg
				Display( 1, title_A:x:title_B, msg_A:x:msg_B )	
				

				
				objOutlookMsg = objOutlook.CreateItem(0)
				objOutlookRecip=objOutlookMsg.Recipients
				objOutlookRecip.Add(Recip)
				objOutlookMsg.Subject = title_A:x:title_B
				objOutlookMsg.Body = msg_A:x:msg_B:@CRLF 
				objOutlookMsg.Display
				objOutlookMsg.Save
				objOutlookMsg.Send

		;		Message("debug","Sent?")
				
				
				; Add attachments to the message.
				;objOutlookAttach = objOutlookMsg.Attachments
				;objOutlookAttach.Add(AttachmentPath)
				
				
	

				ElseIf inserttotitle && !inserttomsg

				Display( 1, title_A:x:title_B, msg_A )	
				

				objOutlookMsg = objOutlook.CreateItem(0)
				objOutlookMsg.Display
				objOutlookRecip=objOutlookMsg.Recipients
				objOutlookRecip.Add(Recip)
				objOutlookMsg.Subject = title_A:x:title_B
				objOutlookMsg.Body = msg_A:@CRLF 
				objOutlookMsg.Send

				ElseIf !inserttotitle && inserttomsg

				Display( 1, title_A, msg_A:x:msg_B )	
				

				objOutlookMsg = objOutlook.CreateItem(0)
				objOutlookMsg.Display
				objOutlookRecip=objOutlookMsg.Recipients
				objOutlookRecip.Add(Recip)
				objOutlookMsg.Subject = title_A
				objOutlookMsg.Body = msg_A:x:msg_B:@CRLF 
				objOutlookMsg.Send

				ElseIf !inserttotitle && !inserttomsg

				Message("Error","If we aren't incrementing, then why are we using this tool?")
				Exit

				EndIf




				

				Next


				objOutlookRecip = 0
				objOutlookMsg = 0
				objOutlook.Quit();
				objOutlook = 0

				ObjectClose( objOutlookRecip )
				ObjectClose( objOutlookMsg )
				ObjectClose( objOutlook )


				

				return(@retDefault)

			elseif MyDialog_Name == "PushButton_Cancel"        ; Quit
				return(@retDefault)

			endif                                              ; MyDialog_Name
			return(@retDefault)

		case @deCbCheck
			if MyDialog_Name == "CheckBox_1"                   ; cbVariable1 Insert Increment Into Title
				return(@retDefault)

			elseif MyDialog_Name == "CheckBox_2"               ; cbVariable2 Insert Increment Into Message Body
				return(@retDefault)

			endif                                              ; MyDialog_Name
			return(@retDefault)

		case @deEdText
			if MyDialog_Name == "EditBox_titlepa"              ; ebtitlea
				return(@retDefault)

			elseif MyDialog_Name == "EditBox_titlepb"          ; ebtitleb
				return(@retDefault)

			elseif MyDialog_Name == "MultiLineBox_mbpa"        ; mlVariable1
				return(@retDefault)

			elseif MyDialog_Name == "MultiLineBox_mbpb"        ; mlVariable2
				return(@retDefault)

			endif                                              ; MyDialog_Name
			return(@retDefault)

		case @deSpChange
			if MyDialog_Name == "Spinner_1"                    ; spVariable1start 1
				return(@retDefault)

			elseif MyDialog_Name == "Spinner_2"                ; spVariable2stop 2
				return(@retDefault)

			endif                                              ; MyDialog_Name
			return(@retDefault)

		case @deClose                                         ; System menu close event
			return(@retDefault)

	endswitch                                                ; MyDialog_Event
	return(@retDefault)
#EndSubroutine                                              ; End of Dialog Callback MyDialogCallbackProc

;============================================================
;============================================================
;============================================================


MyDialogFormat=`WWWDLGED,6.2`

MyDialogCaption=`ITCT - Incremental Ticket Creation Tool`
MyDialogX=250
MyDialogY=098
MyDialogWidth=318
MyDialogHeight=236
MyDialogNumControls=015
MyDialogProcedure=`MyDialogCallbackProc`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0

MyDialog001=`009,213,078,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"Create Tickets",1,10,@csDefButton,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`269,213,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Quit",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`009,057,296,012,EDITBOX,"EditBox_titlepa",ebtitlea,DEFAULT,DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog004=`009,025,046,012,SPINNER,"Spinner_1",spVariable1start,"1",DEFAULT,40,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog005=`075,025,044,012,SPINNER,"Spinner_2",spVariable2stop,"2",DEFAULT,50,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog006=`009,011,044,012,STATICTEXT,"StaticText_1",DEFAULT,"Increment Start",DEFAULT,60,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog007=`075,011,044,012,STATICTEXT,"StaticText_2",DEFAULT,"Increment Stop",DEFAULT,70,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog008=`009,043,044,012,STATICTEXT,"StaticText_3",DEFAULT,"Title Part A",DEFAULT,80,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog009=`009,075,072,012,CHECKBOX,"CheckBox_1",cbVariable1,"Insert Increment Into Title",1,90,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog010=`041,091,264,012,EDITBOX,"EditBox_titlepb",ebtitleb,DEFAULT,DEFAULT,100,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog011=`009,091,030,012,STATICTEXT,"StaticText_4",DEFAULT,"Title Part B",DEFAULT,110,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog012=`009,117,296,030,MULTILINEBOX,"MultiLineBox_mbpa",mlVariable1,DEFAULT,DEFAULT,120,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog013=`009,151,098,012,CHECKBOX,"CheckBox_2",cbVariable2,"Insert Increment Into Message Body",1,130,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog014=`009,107,080,012,STATICTEXT,"StaticText_5",DEFAULT,"Message Body Part A",DEFAULT,140,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog015=`009,169,296,038,MULTILINEBOX,"MultiLineBox_mbpb",mlVariable2,DEFAULT,DEFAULT,150,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MyDialog")

td

Not sure what is causing your problem but since you mentioned Windows 10, I assume the problem started when you migrated to Windows 10 from some other version of Windows.  You might want to consider perusing the latest Outlook VBA documentation to determine if you are using the object model as dictated by MSFT.  The object model can be found here:

https://docs.microsoft.com/en-us/office/vba/api/overview/outlook
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

FWIW, I was able to get rid of the error when sending consecutive email messages by commenting out the display line

Code  winbatch Select
;objOutlookMsg.Display
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

notds

Clean install of win 10.

Thanks for the input I'll give it a shot :)

EricLee

Outlook 2016 was requiring a secret phrase at whatever point I rebooted, and I found that the Generic Credential being made in Credential Manager had a Persistence setting of "Session" which means it just endured as long as I was signed on.

SMF spam blocked by CleanTalk