macro that runs another macro in another worksheet

Ruben

New member
Joined
May 18, 2017
Messages
1
Reaction score
0
Points
0
Hi Folks,

Im trying to create a macro that runs another macro in another worksheet.

Ive managed to run the macro on the other sheet(which btw is to save as pdf and send email) but what happens is that it selects the worksheet that is active instead of the actual worksheet that i want to print.


_____________________
Sub AttachActiveSheetPDF()
Dim IsCreated As Boolean
Dim i As Long
Dim PdfFile As String, Title As String
Dim OutlApp As Object

' Not sure for what the Title is
Title = Range("A1")
' Define PDF filename
PdfFile = ActiveWorkbook.FullName
i = InStrRev(PdfFile, ".")
If i > 1 Then PdfFile = Left(PdfFile, i - 1)
PdfFile = PdfFile & "_" & ActiveSheet.Name & ".pdf"

' Export activesheet as PDF
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With

' Use already open Outlook if possible
On Error Resume Next
Set OutlApp = GetObject(, "Outlook.Application")
If Err Then
Set OutlApp = CreateObject("Outlook.Application")
IsCreated = True
End If
OutlApp.Visible = True
On Error GoTo 0

' Prepare e-mail with PDF attachment
With OutlApp.CreateItem(0)

' Prepare e-mail
.Subject = Title
.To = "rubenc@gmail.co.uk" ' <-- Put email of the recipient here
.CC = "" ' <-- Put email of 'copy to' recipient here
.Body = "Hi," & vbLf & vbLf _
& "The In-Sync Expenses Report is attached in PDF format." & vbLf & vbLf _
& "Regards," & vbLf _
& "RAM TEAM" & vbLf & vbLf
.Attachments.Add PdfFile

' Try to send
On Error Resume Next
.Send
Application.Visible = True
If Err Then
MsgBox "E-mail was not sent", vbExclamation
Else
MsgBox "E-mail successfully sent", vbInformation
End If
On Error GoTo 0

End With

' Delete PDF file
Kill PdfFile

' Quit Outlook if it was created by this code
If IsCreated Then OutlApp.Quit

' Release the memory of object variable
Set OutlApp = Nothing

End Sub

______________

So this is the code that selects the excel sheet and sends it.

____________

On the other workbook i have a button running this code:


Sub printwk22()
Application.Run "'In-Sync Expenses wk22.xlsm'!AttachActiveSheetPDF"
End Sub
______

Now instead of getting the original sheet that i want to send, it prints the workbook where the button is.

Can you guys help me running this macro in order to select from 'In-Sync Expenses wk22.xlsm and print ?

Thanks !
 
Back
Top