PDA

View Full Version : Solved: Reference Libraries



samuelwright
12-07-2005, 05:15 AM
Hi all

I wrote some macros in Outlook 2003, which I want to give to someone who runs Outlook 2000. I worked out how to do this by copying the my VBAProjectFile and the outcmd.dat file into their Outlook profile in their local documents and settings. However, Outlook 2003 uses the Outlook Reference Library 11.0, whereas Outlook 2000 uses an earlier library, e.g. version 9.0.

I didnt think this would make a difference, but it does unfortunately. Will the code I have written below work on Office 2000 (I have my suspicions with the ActiveInspector property: what do you think) ? Please can someone try this in Outlook 2000 and maybe think of any suggestions for modifying the procedures if they cannot get the correct library?

Here is the code:


'---Sub that calls the userform, containing a textbox called SaveDate
'---a combobox called Class, a textbox called title, a checkbox called
'---InternetTick and a textbox called FileName. Also 2 buttons called
'---okButton and CancelButton.

Public objNewMail As Outlook.MailItem

Sub SubjectName()
SubjectNameForm.Show
End Sub

Option Explicit

'---Declarations
Dim pm As String
Dim TodayDate As String
Dim internetauthorised As String
Dim replysubject As String

'---UserForm Set Up

Private Sub UserForm_Initialize()
Set objNewMail = Outlook.ActiveInspector.CurrentItem
replysubject = ""

'---Sets Date
SaveDate = Format(Date, "yyyymmdd")

'---Sets Classification menu
Class.AddItem ("U - Unrestricted")
Class.AddItem ("P - Private")

'---If Email is a Re/Fwd, ensures email does not start with RE:FW etc

If Left(objNewMail.Subject, 3) = "RE:" Or Left(objNewMail.Subject, 3) = "FW:" _
Then Title = objNewMail.Subject

End Sub

Private Sub Title_Enter()
If SubjectNameForm.Title.BackColor <> RGB(255, 255, 255) Then
SubjectNameForm.Title.BackColor = RGB(255, 255, 255)
Title = ""
End If
End Sub

Private Sub Update_Filename()

pm = Left(Class, 1)
If InternetTick.Value = True Then internetauthorised = "Internet-Authorised:" _
Else internetauthorised = ""
FileName = internetauthorised & SaveDate & " " & pm & " " & Title
End Sub

'---These sub updates the file name in the preview window as the user
'---changes the options

Private Sub Title_Change()
Call Update_Filename
End Sub

Private Sub SaveDate_Change()
Call Update_Filename
End Sub

'---Gathers all the infomation from the options and presents it to
'---the email subject line

Private Sub okButton_click()
objNewMail.Subject = FileName
Unload Me
End Sub

'---This button exits the form

Private Sub CancelButton_Click()
Unload Me
End Sub

mvidas
12-07-2005, 07:55 AM
Hi samuel,

I use ol2000. I created a userform named SubjectNameForm like you described, and set everything up as your comments describe. There were no compile errors, and the ActiveInspector method is a valid one for ol2000.

I did get an error when the userform was shown and there was no message being edited or anything. (you may want to check to see if activeinspector is nothing to avoid this), but from my basic testing it seemed to work good otherwise

Matt

samuelwright
12-07-2005, 08:44 AM
Hi mvidas

May I ask which Reference Libraries you used in Outlook 2000? I will compare this list with what my friend is using, and see if he has got what is required.

PS, a KB entry by MOS Master (thanks!!) helped me to solve the problem with the userform error if no message is being edited. See below

http://www.vbaexpress.com/kb/getarticle.php?kb_id=502 :thumb

mvidas
12-07-2005, 09:26 AM
Looking through your code you shouldn't need many references.. in all honesty I have quite a few setup here.
-Visual Basic For Applications
-Microsoft Outlook 9.0 Object Library
-OLE Automation
-Microsoft Office 9.0 Object Library
-Microsoft Excel 9.0 Object Library
-Microsoft VBScript Regular Expressions 5.5
-Microsoft CDO for Windows 2000 LIbrary
-Microsoft Scripting Runtime
-Microsoft Forms 2.0 Object Library

I can't imagine you'd need more than the VBA/Outlook/OLE libraries, but you could need Office, CDO, or Forms 2.0 perhaps.

I didn't look at that entry yet, but when I tried your original code above without a message being edited, I got the "object variable or with block not set" error.

samuelwright
12-07-2005, 09:46 AM
Thanks I will get back to you on that one after I have quizzed my friend! Probably tommorrow...: pray2:

PS I took the code that MOSMASTER wrote in his KB entry and then got the button he created to show the userform that I created. In this way, the button only appears when a new message (or reply) is being written. It is far better than my code! But then I guess that is why he is a VBAX guru and I am a mere mortal.

Howard Kaikow
12-07-2005, 10:48 PM
Hi all

I wrote some macros in Outlook 2003, which I want to give to someone who runs Outlook 2000. I worked out how to do this by copying the my VBAProjectFile and the outcmd.dat file into their Outlook profile in their local documents and settings. However, Outlook 2003 uses the Outlook Reference Library 11.0, whereas Outlook 2000 uses an earlier library, e.g. version 9.0.

I didnt think this would make a difference, but it does unfortunately. Will the code I have written below work on Office 2000 (I have my suspicions with the ActiveInspector property: what do you think) ? Please can someone try this in Outlook 2000 and maybe think of any suggestions for modifying the procedures if they cannot get the correct library?

Here is the code:


'---Sub that calls the userform, containing a textbox called SaveDate
'---a combobox called Class, a textbox called title, a checkbox called
'---InternetTick and a textbox called FileName. Also 2 buttons called
'---okButton and CancelButton.

Public objNewMail As Outlook.MailItem

Sub SubjectName()
SubjectNameForm.Show
End Sub

Option Explicit

'---Declarations
Dim pm As String
Dim TodayDate As String
Dim internetauthorised As String
Dim replysubject As String

'---UserForm Set Up

Private Sub UserForm_Initialize()
Set objNewMail = Outlook.ActiveInspector.CurrentItem
replysubject = ""

'---Sets Date
SaveDate = Format(Date, "yyyymmdd")

'---Sets Classification menu
Class.AddItem ("U - Unrestricted")
Class.AddItem ("P - Private")

'---If Email is a Re/Fwd, ensures email does not start with RE:FW etc

If Left(objNewMail.Subject, 3) = "RE:" Or Left(objNewMail.Subject, 3) = "FW:" _
Then Title = objNewMail.Subject

End Sub

Private Sub Title_Enter()
If SubjectNameForm.Title.BackColor <> RGB(255, 255, 255) Then
SubjectNameForm.Title.BackColor = RGB(255, 255, 255)
Title = ""
End If
End Sub

Private Sub Update_Filename()

pm = Left(Class, 1)
If InternetTick.Value = True Then internetauthorised = "Internet-Authorised:" _
Else internetauthorised = ""
FileName = internetauthorised & SaveDate & " " & pm & " " & Title
End Sub

'---These sub updates the file name in the preview window as the user
'---changes the options

Private Sub Title_Change()
Call Update_Filename
End Sub

Private Sub SaveDate_Change()
Call Update_Filename
End Sub

'---Gathers all the infomation from the options and presents it to
'---the email subject line

Private Sub okButton_click()
objNewMail.Subject = FileName
Unload Me
End Sub

'---This button exits the form

Private Sub CancelButton_Click()
Unload Me
End Sub



I've not looked at your code, you'll have to test that yourself with Outlook 2000.

If you need to distribute VBAProject.otm and have the code work in both Outlook 2000 and Outlook 2003, you have to do two thingsL

1. Run the code in Outlook 2000 to see whether the code includes critters that work in 2003, but not in 2000.

2. You then have to do one of the following:

a. Preferred is to build te OTM using Outlook 2000, not Outlook 2003. iN this case, you would then have to test the Outlook 2000 created OTM in Outlokk 2003 to see whether things still work.

b. Not at all preferred, but if you do not have access to Outlook 2000, then you need to redo the OTM in Outlook 2003 using late binding. But, and I do have a big butt, it wil lstil lbe necessary to test using Outlook 2000, as in a. supra.

samuelwright
12-08-2005, 01:51 AM
Hey Howard

Problem solved I think...according to my friend, I wrote the VBAProject and referenced MS Office 11.0 Object Library, whereas it needs MS Office 9.0 (which I had not selected). They selected v9.0, and hey presto! It works.

Thanks for your help!:friends:

Howard Kaikow
12-08-2005, 05:51 AM
Hey Howard

Problem solved I think...according to my friend, I wrote the VBAProject and referenced MS Office 11.0 Object Library, whereas it needs MS Office 9.0 (which I had not selected). They selected v9.0, and hey presto! It works.

Thanks for your help!:friends:

yes, if they explicitly change the reference it will work, but in a typical distribution, you cannot expect that the recipient will know how, or wish, to change a reference.

samuelwright
12-08-2005, 06:51 AM
Oh right

is there a way of selecting which library reference is used by coding it into the VBA? Or is that some sort of mind-bending, self referencing, never ending loop?:nervous:

Howard Kaikow
12-08-2005, 07:53 AM
Oh right

is there a way of selecting which library reference is used by coding it into the VBA? Or is that some sort of mind-bending, self referencing, never ending loop?:nervous:

No, mostly because the outlook object model does not expose the VBAProject in VBA, so you cannot do lots of useful things.

mvidas
12-08-2005, 11:58 AM
You could add the reference 9.0 on the distribution, and when users of 11.0 get it the reference will be automatically updated.

You could also just dim all the Outlook objects as simply 'Object', and use late binding to refer to outlook, eliminating the need to reference either of them.
Matt

Howard Kaikow
12-08-2005, 02:25 PM
You could add the reference 9.0 on the distribution, and when users of 11.0 get it the reference will be automatically updated.

You could also just dim all the Outlook objects as simply 'Object', and use late binding to refer to outlook, eliminating the need to reference either of them.
Matt

i had already suggested those alternatives, did not get a response to those suggestions.

samuelwright
12-09-2005, 01:38 AM
Hey guys, sorry you will have to forgive my ignorance

Im not really sure what late binding is, and when I try and to add reference library 9.0, I cannot find it on my list of libraries...sorry

Howard Kaikow
12-09-2005, 03:31 AM
In order to add a reference to the Outlook 9 library, you need to develop the OTM file on a system that has Outlook 2000.

samuelwright
12-09-2005, 06:00 AM
fair enough...what i am going to do is send teh VBA project OTM file to people on 2000 who are VBA-Savvy, then they can resave it using the correct liberaries and then redistribute it at their end. Should be ok...