Results 1 to 4 of 4

combine command button and a macro code

Threaded View

  1. #1
    Forum Contributor
    Join Date
    08-18-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    490

    combine command button and a macro code

    Hey guys,

    I have a command button which has the following code:

    Private Sub CommandButton1_Click()
    Dim path As String
    Dim filename1 As String
    Dim filename2 As String
        
    path = "G:\Invoices\"
    filename1 = Range("C3").Text
    filename2 = Range("Q42").Text
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:=path & filename1 & "-" & filename2 & ".xlsx", FileFormat:=xlOpenXMLWorkbook, Password:="Password123"
    Application.DisplayAlerts = True
    
    End Sub

    And a macro code :

    Sub TST()
        Dim TempFilePath As String
        Dim TempFileName As String
        Dim FileFullPath As String
        
        TempFilePath = Environ$("temp") & "\"
        TempFileName = ActiveSheet.Range("C3") & "_" & ActiveSheet.Range("Q42")
        FileFullPath = TempFilePath & TempFileName
        
        ActiveSheet.ExportAsFixedFormat 0, FileFullPath
        
        On Error Resume Next
        With CreateObject("Outlook.Application").createitem(0)
            .To = "[email protected]"
            .Subject = "Test"
            .Body = "test"
            .Attachments.Add FileFullPath & ".pdf" '--- full path of the pdf where it is saved
            .Send   'or use .Display to show you the email before sending it.
        End With
        On Error GoTo 0
        Kill FileFullPath & ".pdf"
    End Sub
    I need to combine them as one.

    How can i Do it?
    Last edited by anilpatni1234; 01-29-2018 at 05:11 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. need macro code to open new outlook email with text for the command button
    By Giri.hb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-28-2016, 10:02 AM
  2. VBA code to create command button. Print all sheets then delete command button.
    By Declamatory in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-15-2015, 05:18 PM
  3. [SOLVED] Code works in macro but not command button
    By datafiend in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-10-2014, 08:06 PM
  4. Macro Command Button: Combine Save As CSV and Delete Unsed Rows Macros
    By mustng_sally in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-15-2013, 10:41 AM
  5. [SOLVED] code behind the command button that runs another macro
    By Vogelmann in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-10-2012, 06:04 AM
  6. Macro to create Command Button and assign code
    By dagindi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-07-2011, 09:19 AM
  7. Code created in a Macro not working for a Command Button
    By Amber_D_Laws in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-13-2006, 06:40 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