+ Reply to Thread
Results 1 to 7 of 7

Macro works in one workbook but not in another

  1. #1
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Macro works in one workbook but not in another

    This program will take a sheet and send it as an embedded email. It works perfectly in a workbook with worksheets (sheet1)(sheet2)(sheet3)

    For some reason when I enter this code into a workbook I actually need to use it for whos worksheet name is (Recap) it sends the email just fine BUT the contents of the mail are blank. In other words it does not show the worksheet.

    Any ideas?


    Sub Mail_ActiveSheet_Body()
    Dim OutApp As Outlook.Application
    Dim OutMail As Outlook.MailItem
    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    With OutMail
    .To = "[email protected]"
    .CC = ""
    .BCC = ""
    .Subject = "This is the Subject line"
    .HTMLBody = RangetoHTML2
    .Send 'or use .Display
    End With
    Application.ScreenUpdating = True
    Set OutMail = Nothing
    Set OutApp = Nothing
    End Sub

  2. #2
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651
    Shellfish bump.

    Sorry I have been working on fixing it. and I’ll be…… it just wont work right.

  3. #3
    Ron de Bruin
    Guest

    Re: Macro works in one workbook but not in another

    If you want to send the whole sheet use this
    http://www.rondebruin.nl/mail/folder3/mail2.htm


    The example you use is for sending the selection
    This is the page with the code
    http://www.rondebruin.nl/mail/folder3/mail4.htm


    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "sungen99" <[email protected]> wrote in message
    news:[email protected]...
    >
    > This program will take a sheet and send it as an embedded email. It
    > works perfectly in a workbook with worksheets (sheet1)(sheet2)(sheet3)
    >
    > For some reason when I enter this code into a workbook I actually need
    > to use it for whos worksheet name is (Recap) it sends the email just
    > fine BUT the contents of the mail are blank. In other words it does
    > not show the worksheet.
    >
    > Any ideas?
    >
    >
    > Sub Mail_ActiveSheet_Body()
    > Dim OutApp As Outlook.Application
    > Dim OutMail As Outlook.MailItem
    > Application.ScreenUpdating = False
    > Set OutApp = CreateObject("Outlook.Application")
    > Set OutMail = OutApp.CreateItem(0)
    > With OutMail
    > To = "[email protected]"
    > CC = ""
    > BCC = ""
    > Subject = "This is the Subject line"
    > HTMLBody = RangetoHTML2
    > Send 'or use .Display
    > End With
    > Application.ScreenUpdating = True
    > Set OutMail = Nothing
    > Set OutApp = Nothing
    > End Sub
    >
    >
    > --
    > sungen99
    > ------------------------------------------------------------------------
    > sungen99's Profile: http://www.excelforum.com/member.php...fo&userid=9144
    > View this thread: http://www.excelforum.com/showthread...hreadid=505316
    >




  4. #4
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651
    Ron when i use that code i get a compile error.

    Sub or Function not defined.

    the code its pointing too is:

    .HTMLBody = SheetToHTML(ActiveSheet)

    it does not like the "SheetToHTML(ActiveSheet)" part.

    am i missing a refenrence perhaps?

  5. #5
    Ron de Bruin
    Guest

    Re: Macro works in one workbook but not in another

    You miss the function that is on the webpage
    Copy it also in the module

    Like this

    Sub Mail_ActiveSheet_Body()
    Dim OutApp As Outlook.Application
    Dim OutMail As Outlook.MailItem
    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(olMailItem)
    With OutMail
    .To = "[email protected]"
    .CC = ""
    .BCC = ""
    .Subject = "This is the Subject line"
    .HTMLBody = SheetToHTML(ActiveSheet)
    .Send 'or use .Display
    End With
    Application.ScreenUpdating = True
    Set OutMail = Nothing
    Set OutApp = Nothing
    End Sub


    Public Function SheetToHTML(sh As Worksheet)
    'Function from **** Kusleika his site
    'http://www.*****-clicks.com/excel/sheettohtml.htm
    'Changed by Ron de Bruin 04-Nov-2003
    Dim TempFile As String
    Dim Nwb As Workbook
    Dim myshape As Shape
    Dim fso As Object
    Dim ts As Object
    sh.Copy
    Set Nwb = ActiveWorkbook
    For Each myshape In Nwb.Sheets(1).Shapes
    myshape.Delete
    Next
    TempFile = Environ$("temp") & "/" & _
    Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
    Nwb.SaveAs TempFile, xlHtml
    Nwb.Close False
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
    SheetToHTML = ts.ReadAll
    ts.Close
    Set ts = Nothing
    Set fso = Nothing
    Set Nwb = Nothing
    Kill TempFile
    End Function



    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "sungen99" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Ron when i use that code i get a compile error.
    >
    > Sub or Function not defined.
    >
    > the code its pointing too is:
    >
    > HTMLBody = SheetToHTML(ActiveSheet)
    >
    > it does not like the "SheetToHTML(ActiveSheet)" part.
    >
    > am i missing a refenrence perhaps?
    >
    >
    > --
    > sungen99
    > ------------------------------------------------------------------------
    > sungen99's Profile: http://www.excelforum.com/member.php...fo&userid=9144
    > View this thread: http://www.excelforum.com/showthread...hreadid=505316
    >




  6. #6
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651
    AHHHHHHHHHH THANK YOU!!!!!!

    i understand,

    Is there a way to send A1-P100
    Last edited by sungen99; 01-26-2006 at 02:23 PM.

  7. #7
    Ron de Bruin
    Guest

    Re: Macro works in one workbook but not in another

    Hi sungen99

    Instead of
    .HTMLBody = SheetToHTML(ActiveSheet)

    You can also use this

    ..HTMLBody = SheetToHTML(Sheets("YourSheetName"))




    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "sungen99" <[email protected]> wrote in message
    news:[email protected]...
    >
    > AHHHHHHHHHH THANK YOU!!!!!!
    >
    > i understand. been working on this for 4 hours now.. hehe..
    >
    >
    > --
    > sungen99
    > ------------------------------------------------------------------------
    > sungen99's Profile: http://www.excelforum.com/member.php...fo&userid=9144
    > View this thread: http://www.excelforum.com/showthread...hreadid=505316
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1