creating a macro

  • Thread starter Thread starter tpitman
  • Start date Start date
T

tpitman

I would like to create a macro which would insert some default text i
the subject line of a new mail
 
Sub MyMail()
Dim objOL as Outlook.Application
Dim objMail as Outlook.MailItem

Set objOL = CreateObject("Outlook.Application")
Set objMail = objOL.CreateItem(olMailItem)
objMail.Subject = "some default text"
objMail.Display

Set objOL = Nothing
Set objMail = Nothing
End Sub
 
Now I have created the new message with the default test in the subjec
line, I would like to open the "add attachement" window within the sam
code
 
Try this:

Dim objCBs As office.CommandBars, objCBP As office.CommandBarButton

Set objCBs = Application.ActiveInspector.CommandBars
Set objCBP = objCBs.FindControl(, 1079) 'RUN THE INSERT FILE MENU
COMMAND
objCBP.Execute
 
Many thanks for this, but the above code produces an error.
"Object variable or block variable not set
 
What statement produces the error? And where how are the objects in that
statement instantiated?

Also note: The newsgroup interface you are using apparently does not quote
earlier messages in the thread, making your latest message so short on
detail that you risk not getting the answer you're looking for. Please take
the time to quote the original message.
 
Make sure that you have a reference set to the Microsoft Office x.0 Object
Library.
 
Re: creating a macro

tpitman said:
Now I have created the new message with the default test in th subject
line, I would like to open the "add attachement" window within th same

Try this:

Dim objCBs As office.CommandBars, objCBP As office.CommandBarButton

Set objCBs = Application.ActiveInspector.CommandBars
Set objCBP = objCBs.FindControl(, 1079) 'RUN THE INSERT FILE MENU
COMMAND
objCBP.Execute

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


Unfortunatley, this produces a Error '91' message
 
Re: creating a macro

tpitman said:
Now I have created the new message with the default test in th subject
line, I would like to open the "add attachement" window within th same

Try this:

Dim objCBs As office.CommandBars, objCBP As office.CommandBarButton

Set objCBs = Application.ActiveInspector.CommandBars
Set objCBP = objCBs.FindControl(, 1079) 'RUN THE INSERT FILE MENU
COMMAND
objCBP.Execute

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


Unfortunatley, this produces a Error '91' message
 
Do you have a reference set to the Microsoft Office Object library in your
project? Also, ActiveInspector assumes an open e-mail (or other item)
window.

You can trap for an ActiveInspector by declaring another variable:

Dim objInsp as ActiveInspector

Set objInsp = Application.ActiveInspector

If Not objInsp Is Nothing Then
'do stuff
Else
'don't do stuff
End If
 
Re: creating a macro
Do you have a reference set to the Microsoft Office Object library in
your
project? Also, ActiveInspector assumes an open e-mail (or other item)
window.

You can trap for an ActiveInspector by declaring another variable:

Dim objInsp as ActiveInspector

Set objInsp = Application.ActiveInspector

If Not objInsp Is Nothing Then
'do stuff
Else
'don't do stuff
End If

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault


tpitman said:
Re: creating a macro



Try this:

Dim objCBs As office.CommandBars, objCBP As office.CommandBarButton

Set objCBs = Application.ActiveInspector.CommandBars
Set objCBP = objCBs.FindControl(, 1079) 'RUN THE INSERT FILE MENU
COMMAND
objCBP.Execute

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/



Unfortunatley, this produces a Error '91' message.

I have now found that the problem was that I had checked the "use
Microsoft Word to edit mail messages" under mail format.

Once I had unchecked this, the code added to open the attachments
windows, worked fine.
*This window defaults to "My Documents". Is there a way of adding code
to open a different folder?*
 
Re: creating a macro
Do you have a reference set to the Microsoft Office Object library i
your
project? Also, ActiveInspector assumes an open e-mail (or other item)
window.

You can trap for an ActiveInspector by declaring another variable:

Dim objInsp as ActiveInspector

Set objInsp = Application.ActiveInspector

If Not objInsp Is Nothing Then
'do stuff
Else
'don't do stuff
End If

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault


tpitman said:
Re: creating a macro



Try this:

Dim objCBs As office.CommandBars, objCBP As office.CommandBarButton

Set objCBs = Application.ActiveInspector.CommandBars
Set objCBP = objCBs.FindControl(, 1079) 'RUN THE INSERT FILE MENU
COMMAND
objCBP.Execute

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/



Unfortunatley, this produces a Error '91' message.

I have now found that the problem was that I had checked the "us
Microsoft Word to edit mail messages" under mail format.

Once I had unchecked this, the code added to open the attachment
windows, worked fine.
*This window defaults to "My Documents". Is there a way of adding cod
to open a different folder?
 
There is no VBA way to control the default folder location for the insert
file dialog. AFAIK, you can't do it with the registry anyway. You could
use the Common Dialog Control/Class; it allows you to set the default
folder.
 
Back
Top