+ Reply to Thread
Results 1 to 15 of 15

Attach a single worksheet(not the workbook) to email using Excel UserForm Command button

  1. #1
    Registered User
    Join Date
    05-05-2017
    Location
    ALexandria, vA
    MS-Off Ver
    2016
    Posts
    7

    Attach a single worksheet(not the workbook) to email using Excel UserForm Command button

    I am not well versed in vba but have understood enough to create a user feedback form.

    What I am trying to do is email a single worksheet (which is the the first sheet because that is used to collect the data, the second sheet which is what I want to attach is where the data is stored.

    I have been doing research online and the only two solutions I can find is either email the active sheet or email the entire workbook. I feel the code I have is close to what I want to accomplish but I want it to send sheet 2 as the attachment and not sheet 1.

    Dim SourceWB As Workbook
    Dim DestinWB As Workbook
    Dim OutlookApp As Object
    Dim OutlookMessage As Object
    Dim TempFileName As Variant
    Dim ExternalLinks As Variant
    Dim TempFilePath As String
    Dim FileExtStr As String
    Dim DefaultName As String
    Dim UserAnswer As Long
    'Dim x As LongDim
    Dim strDate As String



    'Optimize Code
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.DisplayAlerts = False

    'Copy only selected sheets into new workbook
    ActiveWorkbook.Sheets("Sheet2").Copy //there is where is bugs out
    strDate = Format(Date, "dd-mm-yy") & " " & Format(Time, "h-mm-ss")
    ActiveWorkbook.SaveAs "Part of " & ThisWorkbook.Name _
    & " " & strDate & ".xls"
    Set SourceWB = ActiveWorkbook
    SourceWB.Windows(1).SelectedSheets.Copy
    Set DestinWB = ActiveWorkbook

    Any assistance is greatly appreciated.

    also posted on ozgrid: http://www.ozgrid.com/forum/showthre...844#post791844
    Last edited by jaeda1920; 05-08-2017 at 11:54 AM. Reason: updated to included other post in different forum

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,593

    Re: Attach a single worksheet(not the workbook) to email using Excel UserForm Command butt

    Hi, welcome to the forum
    It's easier and faster if you look at the attached links
    https://www.techonthenet.com/excel/m..._sheet2007.php
    http://www.vbaexpress.com/kb/getarticle.php?kb_id=350
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    05-05-2017
    Location
    ALexandria, vA
    MS-Off Ver
    2016
    Posts
    7

    Re: Attach a single worksheet(not the workbook) to email using Excel UserForm Command butt

    thank you for responding but I'm not trying to email the activeworksheet I am trying to email a separate worksheet in the same workbook (that is hidden from the user) so these examples will not work.
    The userform that collects the data is the activeworksheet (sheet 1)
    The sheet I want to email is the userfeedbackdata (sheet 2) - which is hidden and not the activeworksheet.
    Both are in the same workbook.

    Jaeda

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,593

    Re: Attach a single worksheet(not the workbook) to email using Excel UserForm Command butt

    You can reference it and to the same but I would suggest you unhide it copy it and hide it using the code. It does not have to be the active sheet, just name i correctly in the code.
    Is screen updating is false nobody sees it it just 'happens'

  5. #5
    Registered User
    Join Date
    05-05-2017
    Location
    ALexandria, vA
    MS-Off Ver
    2016
    Posts
    7

    Re: Attach a single worksheet(not the workbook) to email using Excel UserForm Command butt

    I'm not sure I'm following. everytime I use the activesheet code its sends the user excel form. that is not what we need in the email. the actual data which is in sheet 2 needs to be sent. when i do active sheet it only sends the first sheet.

  6. #6
    Registered User
    Join Date
    05-05-2017
    Location
    ALexandria, vA
    MS-Off Ver
    2016
    Posts
    7

    Re: Attach a single worksheet(not the workbook) to email using Excel UserForm Command butt

    Hopefully this screenshot helps. When coding is used to do activesheet, the instructions page is sent, what I need send is the userfeedback sheet.

    I don't want the entire workbook sent because the userform could be activated again by accident and cause confusion. I just want to send the userfeedback sheet.
    win10.jpg

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,593

    Re: Attach a single worksheet(not the workbook) to email using Excel UserForm Command butt

    This code works:

    Please Login or Register  to view this content.

  8. #8
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,593

    Re: Attach a single worksheet(not the workbook) to email using Excel UserForm Command butt

    Just make sure the sheet name you want to send is the correct one

  9. #9
    Registered User
    Join Date
    05-05-2017
    Location
    ALexandria, vA
    MS-Off Ver
    2016
    Posts
    7

    Re: Attach a single worksheet(not the workbook) to email using Excel UserForm Command butt

    So i tried the code and its sort of working, the email never populates, it creates a new workbook but not the email attachement. IT also opens the file throwing the person completely out of the form, the goal is to back to the form once the email is sent.

    I'll keep playing with the code because at least its taking the correct worksheet, now i have to get the email part to go again

  10. #10
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,593

    Re: Attach a single worksheet(not the workbook) to email using Excel UserForm Command butt

    Are you using Outlook? Have you checked Outlook? It doesn't send anything it just opens a blank new message with the file as attachment.
    If the file doesn't contain private or sensitive data, I suggest you attach it, makes it easier.
    The Userform, you will have to write code to close it, send the mail and reopen it.

  11. #11
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,593

    Re: Attach a single worksheet(not the workbook) to email using Excel UserForm Command butt

    It works here, I added a page with a command button that opens a userform with one button to send the worksheet and it works,

    Result in screen capture, the userform remains visible and workheet is sent
    Attached Images Attached Images

  12. #12
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Attach a single worksheet(not the workbook) to email using Excel UserForm Command butt

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

  13. #13
    Registered User
    Join Date
    05-05-2017
    Location
    ALexandria, vA
    MS-Off Ver
    2016
    Posts
    7

    Re: Attach a single worksheet(not the workbook) to email using Excel UserForm Command butt

    sorry, i didn't know. I updated the link

  14. #14
    Registered User
    Join Date
    05-05-2017
    Location
    ALexandria, vA
    MS-Off Ver
    2016
    Posts
    7

    Re: Attach a single worksheet(not the workbook) to email using Excel UserForm Command butt

    so with this code, it works to an extent: It bugged out upon running and I changed the code from worksheets to sheets and is displayed the email in outlook and attached the file.:
    Please Login or Register  to view this content.
    however i can't open the attachment, not recognizing a program to open with which tells me it is not saved as a excel file and I'm not sure where I would update that at and i just want the file name to be simple like userfeedbackrequest.xlsx

    Any thoughts on your code or the code from the other forum I posted on: http://www.ozgrid.com/forum/showthre...844#post791844

  15. #15
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,593

    Re: Attach a single worksheet(not the workbook) to email using Excel UserForm Command butt

    Sorry, my mistake, corrected the code, should work now.
    The resulting attachment is a non-macro-embedded file (.xlsx)
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. I'm Stuck...Userform / Command Button export to worksheet in same workbook
    By KG23 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-03-2016, 08:36 PM
  2. Email data from Specific Rows in Multiple worksheets from Userform Command Button
    By JJFletcher in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-09-2014, 07:07 PM
  3. Need a single command button to display data from 2 Sheets in a UserForm
    By z-eighty2 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-26-2013, 05:30 PM
  4. Replies: 0
    Last Post: 03-14-2013, 01:27 AM
  5. command button VBA to send automated email not workbook or worksheet
    By lpratt in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-08-2012, 11:13 PM
  6. Email worksheet via command button
    By KaFi in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-27-2010, 11:50 PM
  7. How do you set up a submit button to attach worksheet in email?
    By almostthere002@yahoo.com in forum Excel General
    Replies: 1
    Last Post: 09-28-2005, 02:05 PM

Tags for this Thread

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