Hi All
This I think is a bit of a tricky one I have a few sets of code I want to link together seamlessly.
These two codes I have writen in Outlook:
This one saves all the attachments from a selected email into a new folder the user creates (with the inputbox for job number).
This one directs the user to take a screenshot of the program "logis" and then simply opens a word template document .
Now we move to the Word template code here:
This runs the word macro below on document opening.
This justs pastes the captured screen shot into the word doc and saves it as a PDF. Here is my first problem, you see there is the job number inputbox again, is there a way for this macro to use the already set job number (and hence the correct folder to save the pdf to) from the code in Outlook?
Moving on, once this is done there should be a bunch of attachments and this new pdf in the created "job number" folder.
I then have this code which basically just sends a blank email to an address with attachments:
This is fine, however I have one extra question, what code could I use to attach all the files in the job number folder to the email? There could be many files in the folder?
And thats where I am, need to put all the above together (with the fixes) so that it can all run from a button in outlook.
Many thanks in advance.
Cheers
This I think is a bit of a tricky one I have a few sets of code I want to link together seamlessly.
These two codes I have writen in Outlook:
Code:
Public Sub SaveAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem 'Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String
' Get the path to your folder
strFolderpath = "C:\Users\tbaker\Documents\Jobs\"
On Error Resume Next
' Instantiate an Outlook Application object.
Set objOL = CreateObject("Outlook.Application")
' Get the collection of selected objects.
Set objSelection = objOL.ActiveExplorer.Selection
' Set the Attachment folder.
job = InputBox("Enter Job Number")
MkDir strFolderpath & job
strFolderpath = strFolderpath & job & "\"
' Check each selected item for attachments. If attachments exist,
' save them to the strFolderPath folder
For Each objMsg In objSelection
' This code only strips attachments from mail items.
' If objMsg.class=olMail Then
' Get the Attachments collection of the item.
Set objAttachments = objMsg.Attachments
lngCount = objAttachments.Count
strDeletedFiles = ""
If lngCount > 0 Then
For i = lngCount To 1 Step -1
' Save attachment before deleting from item.
' Get the file name.
strFile = objAttachments.Item(i).FileName
' Combine with the path to the Temp folder.
strFile = strFolderpath & strFile
' Save the attachment as a file.
objAttachments.Item(i).SaveAsFile strFile
Next i
End If
Next
ExitSub:
Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub
This one saves all the attachments from a selected email into a new folder the user creates (with the inputbox for job number).
Code:
Sub Opentemplate()
Dim word As Object
Set word = CreateObject("Word.Application")
Template = "C:\Users\tbaker\Documents\Template.docm"
MsgBox ("Set Windows focus on Logis, then click ALT+PRINT SCREEN, then click OK below")
With word
.Documents.Open (Template)
.Visible = True
End With
End Sub
This one directs the user to take a screenshot of the program "logis" and then simply opens a word template document .
Now we move to the Word template code here:
Code:
Sub Document_Open()Screen_Capture_VBA
End Sub
This runs the word macro below on document opening.
Code:
Sub Screen_Capture_VBA()
Selection.Paste
Dim job As String
job = InputBox("Enter Job Number")
Dim DocName As String
DocName = "C:\Users\tbaker\Documents\Jobs\" & job & "\" & job & ".pdf"
ActiveDocument.SaveAs FileName:=DocName, FileFormat:=wdFormatPDF
End Sub
This justs pastes the captured screen shot into the word doc and saves it as a PDF. Here is my first problem, you see there is the job number inputbox again, is there a way for this macro to use the already set job number (and hence the correct folder to save the pdf to) from the code in Outlook?
Moving on, once this is done there should be a bunch of attachments and this new pdf in the created "job number" folder.
I then have this code which basically just sends a blank email to an address with attachments:
Code:
temp = "C:\Users\tbaker\Documents\Jobs\" & job & "\" & job & ".pdf" 'this is the pdf created in word, again you see I need to get the job number from way back at the beginning
Dim objOutl
Set objOutl = CreateObject("Outlook.Application")
Set objMailItem = objOutl.CreateItem(olMailItem)
Application.ScreenUpdating = False
ans = MsgBox("Do you need to add any more attachments?", vbYesNo)
If ans = vbYes Then
AttachFileName = Application.GetOpenFilename("Files (*.**)," & _
"*.**", 1, "Select File", "Open", True)
strEmailAddr = [EMAIL="email.address@domain.com"]email.address@domain.com[/EMAIL]
objMailItem.Recipients.Add strEmailAddr
objMailItem.Body = ""
objMailItem.Subject = ""
objMailItem.Attachments.Add temp
For a = LBound(AttachFileName) To UBound(AttachFileName)
objMailItem.Attachments.Add AttachFileName(a)
Next
objMailItem.Send
End If
Set objMailItem = Nothing
Set objOutl = Nothing
Application.ScreenUpdating = True
This is fine, however I have one extra question, what code could I use to attach all the files in the job number folder to the email? There could be many files in the folder?
And thats where I am, need to put all the above together (with the fixes) so that it can all run from a button in outlook.
Many thanks in advance.
Cheers