+ Reply to Thread
Results 1 to 5 of 5

Cut and Paste Macro

  1. #1
    Forum Contributor
    Join Date
    08-29-2014
    Location
    Chicago, IL
    MS-Off Ver
    2014
    Posts
    164

    Cut and Paste Macro

    I have the following VBA code that cuts a range of cells and emails the range. I would like the cut range of data to also paste onto a separate tab called 'sent'. The data should paste onto the next available blank row.



    Sub SendRange()
    'Update 20131209
    Dim xFile As String
    Dim xFormat As Long
    Dim Wb As Workbook
    Dim Wb2 As Workbook
    Dim Ws As Worksheet
    Dim FilePath As String
    Dim FileName As String
    Dim OutlookApp As Object
    Dim OutlookMail As Object
    Dim WorkRng As Range
    xTitleId = "KutoolsforExcel"
    Set WorkRng = Application.Selection
    Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set Wb = Application.ActiveWorkbook
    Wb.Worksheets.Add
    Set Ws = Application.ActiveSheet
    WorkRng.Cut Ws.Cells(1, 1)
    Ws.Copy
    Set Wb2 = Application.ActiveWorkbook
    Select Case Wb.FileFormat
    Case xlOpenXMLWorkbook:
    xFile = ".xlsx"
    xFormat = xlOpenXMLWorkbook
    Case xlOpenXMLWorkbookMacroEnabled:
    If Wb2.HasVBProject Then
    xFile = ".xlsm"
    xFormat = xlOpenXMLWorkbookMacroEnabled
    Else
    xFile = ".xlsx"
    xFormat = xlOpenXMLWorkbook
    End If
    Case Excel8:
    xFile = ".xls"
    xFormat = Excel8
    Case xlExcel12:
    xFile = ".xlsb"
    xFormat = xlExcel12
    End Select
    FilePath = Environ$("temp") & "\"
    FileName = Wb.Name & Format(Now, "dd-mmm-yy h-mm-ss")
    Set OutlookApp = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApp.CreateItem(0)
    Wb2.SaveAs FilePath & FileName & xFile, FileFormat:=xFormat
    With OutlookMail
    .To = ThisWorkbook.Sheets("Combined").Range("r8")
    .CC = ""
    .BCC = ""
    .Subject = "Pending Order Work Request"
    .Body = "Please complete the pending order you are currently working and then begin working this list. "
    .Attachments.Add Wb2.FullName
    .Send
    End With
    Wb2.Close
    Kill FilePath & FileName & xFile
    Set OutlookMail = Nothing
    Set OutlookApp = Nothing
    Ws.Delete
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,486

    Re: Cut and Paste Macro

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    08-29-2014
    Location
    Chicago, IL
    MS-Off Ver
    2014
    Posts
    164

    Re: Cut and Paste Macro

    thanks, where would this go in the current code?

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Cut and Paste Macro

    Maybe:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    08-29-2014
    Location
    Chicago, IL
    MS-Off Ver
    2014
    Posts
    164

    Re: Cut and Paste Macro

    nevermind, thanks. that worked.

+ 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. [SOLVED] Simple copy and paste macro- Paste special help needed.
    By hernancrespo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2012, 07:02 AM
  2. RECORDED MACRO PASTE'S DATE DIFFERENTLY TO MANUAL PASTE
    By Pauldecan in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM
  3. [SOLVED] RECORDED MACRO PASTE'S DATE DIFFERENTLY TO MANUAL PASTE
    By Pauldecan in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM
  4. [SOLVED] Copy and Paste macro needs to paste to a changing cell reference
    By loulou in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2005, 07:06 AM

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