Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default save and email button

Hi,
I've been to Ron DeBruin's site and have borrowed some code from there as
well as some info from other posts here trying t o cobble together the right
set of instructions to do the following in Excel2003:

I have a protected workbook with protected worksheets that is a *.xlt
(template) file.

The only sheet that my 'user' sees is a quote form - they select a set of
criteria and I return a price.

My users are all remote from our offices and I want to have a 'save and
register' macro on that form that saves a copy of the workbook on their c
drive [ c:\quotes\"wb.name" ] and email a copy of the workbook to a monitored
email address ).

Since I want this to be the only way a user can save the quote I also want
to disable the "save" and "save as" File menu options

So based on what I gleaned from these sources I have the following:

In the 'ThisWorkbook' module:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

End Sub
'Removes the save button from the toolbar and removes save from file menu
'User should only save by using save command button

In the Sheet1 code:

Public MySave As Boolean

Sub SaveAndEmailtoRegisterQuote()

MySave = True
Dim iMsg As Object
Dim iConf As Object
Dim wb As Workbook
Dim WBname As String
' Dim sPath As String
' Dim Flds As Variant

Application.ScreenUpdating = False
Set wb = ActiveWorkbook

' It will save a copy of the file in C:\Quotes\ with a Date and Time
stamp
WBname = ActiveSheet.Range("ProjectName") & " " & Format(Now,
"dd-mm-yy h-mm-ss") & ".xls"
wb.SaveCopyAs "C:\Quotes\" & WBname

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

' iConf.Load -1 ' CDO Source Defaults
' Set Flds = iConf.Fields
' With Flds
'
..Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Fill in
your SMTP server here"
'
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
' .Update
' End With

With iMsg
Set .Configuration = iConf
.To = " & ";" &
Sheets("Sheet1").Range("SalesRep_EmailAddress").Va lue
.CC = "
.BCC = ""
.From = Sheets("Sheet1").Range("Contact_EmailAddress").Val ue
.Subject = "This is a test"
.TextBody = "This is the body text"
.AddAttachment "C:\Quotes\" & WBname
.Send
End With

'If you not want to delete the file you send delete this line
' Kill "C:\Quotes?" & WBname

Set iMsg = Nothing
Set iConf = Nothing
Set wb = Nothing
Application.ScreenUpdating = True

If Not MySave Then
Cancel = True
Else
MySave = False
End If
End Sub


With the "Sub SaveAndEmailtoRegisterQuote()" assigned to the button on my
worksheet as a macro.

I also set up a c:\quotes\ directory

I followed RdB's hint about setting the reference to Microsoft Outlook 11.0
Object Library (this is the version that matches my Excel version in the
reference list).

When I run the code (click the button) I get the following:

"System Error: &H80040220 (-2147220960)"

Anyone feel like helping this newbie figure out where the heck he's gone
wrong?

Thanks in advance,

Steve
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default save and email button


The only problem i can see when i tried your code was that you dont
physically open a mail programm such as outlook, i think this might be
why it gives you an automation problem...the rest of your code seemed
to work fine!

Hope this helps, as i am no expert by far!

Regards,
Simon

Steve E wrote:
*

With the "Sub SaveAndEmailtoRegisterQuote()" assigned to the button
on my
worksheet as a macro.

I also set up a c:\quotes\ directory

I followed RdB's hint about setting the reference to Microsoft
Outlook 11.0
Object Library (this is the version that matches my Excel version in
the
reference list).

When I run the code (click the button) I get the following:

"System Error: &H80040220 (-2147220960)"

Anyone feel like helping this newbie figure out where the heck he's
gone
wrong?

Thanks in advance,

Steve *




--
Simon Lloyd
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message2502984.html

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default save and email button

Hi Simon,

Thanks for looking at this for me. I chose to plagerize Ron'd code for the
CDOSYS methodology because I don't think that I have control / knowledge
regarding the email app that my customers (users) are using and liked the
idea that he put forward... and I hate to start compromising at this early
point... or did I miss-understand the point of Ron's code? This is what I am
trying to work from: http://www.rondebruin.nl/cdo.htm
but adding the code to disable the save and saveas menu and toolbar options
to force the 'registration' via email.
Do you think I should take a step back and just try and make it work via
Outlook first? (or is that even a step back - I thought it made it more
complicated since I don't have control over what versions of Outlook are in
my user group?

Help!!!

Steve



"Simon Lloyd" wrote:


The only problem i can see when i tried your code was that you dont
physically open a mail programm such as outlook, i think this might be
why it gives you an automation problem...the rest of your code seemed
to work fine!

Hope this helps, as i am no expert by far!

Regards,
Simon

Steve E wrote:
*

With the "Sub SaveAndEmailtoRegisterQuote()" assigned to the button
on my
worksheet as a macro.

I also set up a c:\quotes\ directory

I followed RdB's hint about setting the reference to Microsoft
Outlook 11.0
Object Library (this is the version that matches my Excel version in
the
reference list).

When I run the code (click the button) I get the following:

"System Error: &H80040220 (-2147220960)"

Anyone feel like helping this newbie figure out where the heck he's
gone
wrong?

Thanks in advance,

Steve *




--
Simon Lloyd
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message2502984.html


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default save and email button

Simon,

Quickly, thanks for looking at this for me. I figured out the things that I
had wrong in my code.
Basically, I had the section of code related to the set.fields line
commented out (as I'd copied it from Ron's site) AND had the file path's
coded as c:/ instead of c:\) once I cleaned these up (and entered my smtp
info correctly!) it works fine.

Thanks again!

Steve

"Steve E" wrote:

Hi Simon,

Thanks for looking at this for me. I chose to plagerize Ron'd code for the
CDOSYS methodology because I don't think that I have control / knowledge
regarding the email app that my customers (users) are using and liked the
idea that he put forward... and I hate to start compromising at this early
point... or did I miss-understand the point of Ron's code? This is what I am
trying to work from: http://www.rondebruin.nl/cdo.htm
but adding the code to disable the save and saveas menu and toolbar options
to force the 'registration' via email.
Do you think I should take a step back and just try and make it work via
Outlook first? (or is that even a step back - I thought it made it more
complicated since I don't have control over what versions of Outlook are in
my user group?

Help!!!

Steve



"Simon Lloyd" wrote:


The only problem i can see when i tried your code was that you dont
physically open a mail programm such as outlook, i think this might be
why it gives you an automation problem...the rest of your code seemed
to work fine!

Hope this helps, as i am no expert by far!

Regards,
Simon

Steve E wrote:
*

With the "Sub SaveAndEmailtoRegisterQuote()" assigned to the button
on my
worksheet as a macro.

I also set up a c:\quotes\ directory

I followed RdB's hint about setting the reference to Microsoft
Outlook 11.0
Object Library (this is the version that matches my Excel version in
the
reference list).

When I run the code (click the button) I get the following:

"System Error: &H80040220 (-2147220960)"

Anyone feel like helping this newbie figure out where the heck he's
gone
wrong?

Thanks in advance,

Steve *




--
Simon Lloyd
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message2502984.html


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Button Save As Application.ExecuteExcel4Macro ("SAVE.AS?() Paul Dennis Excel Discussion (Misc queries) 5 September 18th 06 05:34 PM
Disable save, save as, but allow save via command button TimN Excel Programming 10 September 1st 06 07:05 PM
How to diasble save and save as menu but allow a save button hon123456 Excel Programming 1 June 12th 06 09:50 AM
how to get disk icon on save button of save as dialog like 2000 RichT Excel Discussion (Misc queries) 2 March 9th 06 08:13 PM
save button in excel to save one of the worksheets with a cell value as its name Colin[_9_] Excel Programming 2 September 21st 04 11:28 PM


All times are GMT +1. The time now is 03:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"