It doesn't matter where you copy the .dll, as long as you register it with
this from the command line:
regsvr32 <path to .dll>
However, you need registry keys like these to have it load with Outlook:
[HKEY_CURRENT_USER\Software\Microsoft\Office\Outlook\Addins\<ADD-IN
NAME>.Connect]
"FriendlyName"="<FRIENDLY ADD-IN NAME>."
"Description"="<DESCRIPTION>"
"LoadBehavior"=dword:00000003
"CommandLineSafe"=dword:00000000
Your code looks fine, although you don't need to set the OnAction property
if you declare the button WithEvents. However, you should check to see if
the button exists first; as it stands, you might be creating duplicate
buttons whenever the add-in loads. Lastly, for strict code readability, you
should rename your objWord variable, because it is storing a reference to an
Outlook object.
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job:
http://www.imaginets.com
Blog:
http://blogs.officezealot.com/legault/
:
The previous problem is solved. After I restart my computer, the
button appears on the standard tool bar. Thanks
But, I got another question.
After I create the COM Add-In, is it I copy the DLL file and paste it
in the other machine as well as set the registry? If so, where should
I put the DLL file? And, how to set the registry?
Thanks
OutlookCode.com is the best; otherwise, see MSDN:
Office Developer Center: Outlook:
http://msdn.microsoft.com/office/understanding/outlook/default.aspx
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job:
http://www.imaginets.com
Blog:
http://blogs.officezealot.com/legault/
:
Hi Eric
The macro is working now. Thank you so much.
By the way, do you know any websites are good for learning VBA.
I remember you recommended
http://www.outlookcode.com/d/vb.htm last
time. Anymore sites?
Thanks again.
If the code is exiting at the "If ActiveInspector Is Nothing Then Exit Sub"
line, then this is because you do not have a new e-mail message open. Using
Word as your editor has no effect on the code. Remove the "On Error Resume
Next" line to see exactly where the error is occuring. My guess is because
the objMessage variable evaluates to Nothing, which means you don't have a
message open.
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job:
http://www.imaginets.com
Blog:
http://blogs.officezealot.com/legault/
:
Hi Eric
I check the macro security setting to Medium. I also restart my MS
Outlook. The macro doesn't work still.
I also try to set a breakpoint. I found the macro stop/exit the
subroutine at this statement "If ActionInspector Is Nothing Then Exit
Sub".
When I make the statement "If ActionInspector Is Nothing Then Exit
Sub" as comment, the macro is run. The file in C:\Temp deleted and the
MsgBox is popped up. HOWEVER, it can't attach attachments. I mean no
attachments attach in the email message body.
Is it because I am using MS Word as editor for Outlook message that
make it can't attach attachments? If so, which part of code I need to
change? Because I need to use MS Word as editor for Outlook message.
Thanks
Check your macro security settings from the Tools | Macro| Security menu.
You may have to restart Outlook for any changes to take effect. Then try
running the macro again, making sure that you have a new message window open.
Also try setting a breakpoint on the first line of the procedure to verify
that it is firing at all.
You may also want to review the basics of Outlook VBA. See this link for
some great info:
Visual Basic and VBA Coding in Microsoft Outlook:
http://www.outlookcode.com/d/vb.htm
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job:
http://www.imaginets.com
Blog:
http://blogs.officezealot.com/legault/
:
Hello Eric
When I click Tools -> Macro ->
AttachAllPDFFilesFromFolderToCurrentMessageAndDeleteWhenFinished in
the email message body under Word editor, there is nothing happen. No
files attached. I already create a Temp folder under C: drive and put
a PDF file in the folder. Did I do something wrong?
What I did is:
I open my MS Outlook and reply a message. A email message with Word
editor pop up. Then, I click Tools (on the toolbar)-> Macro->Visual
Basic Editor.
Under VB Editor, I click Tools->References-> Check Microsoft Scripting
Runtime libary checkbox and keep the other default options. Then, I
insert a module and put the coding in the Sub AttachAll...When
Finished() End Sub. Am I doing the right thing?
Anything I haven't done that make it doesn't work?
Thank you
No special considerations for handling WordMail is required. This macro
should do what you want - just change the folder path, make sure the e-mail
is open and set a reference in the Outlook VBA Project to the Microsoft
Scripting Runtime library.
Sub AttachAllPDFFilesFromFolderToCurrentMessageAndDeleteWhenFinished()
On Error Resume Next
Dim objFS As New Scripting.FileSystemObject, objFolder As
Scripting.Folder, objFile As Scripting.File
Dim objMessage As Object, intX As Integer
Dim strFolderPath As String
If ActiveInspector Is Nothing Then Exit Sub
Set objMessage = ActiveInspector.CurrentItem
strFolderPath = "C:\Temp"
Set objFolder = objFS.GetFolder(strFolderPath)
For Each objFile In objFolder.Files
If Right(objFile.Name, 3) = "pdf" Then
objMessage.Attachments.Add (objFile.Path)
objFile.Delete (True)
End If
Next
MsgBox "Your PDF files have been attached, and the sources deleted.",
vbOKOnly + vbInformation, "Operation Complete"
Set objFS = Nothing
Set objFolder = Nothing
Set objFile = Nothing
Set objMessage = Nothing
End Sub
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job:
http://www.imaginets.com
Blog:
http://blogs.officezealot.com/legault/
:
Hi All
I haven't touched Outlook/Word VBA before. So, I'm a newbie.
But, I need to write Outlook/Word Macro to do some works. I say
Outlook/Word Macro because I don't know I should write Outlook or Word
Macro if I want to attach files to Outlook email message using Word as
editor.
My situation is:
I download a number of PDF files from the Internet into a folder
called Temp. I want to write a Outlook/Word Macro to attach all the
PDF files in Temp folder to email message as attachments. Just like
press a button and all files will be attached in the email message.
After all PDF files are attached and sent, all PDF files in Temp
folder will be deleted. Is it possible?
And, can anyone show me some coding on implementing this?
Thank you very much