Copy E-Mail As Text to Clipboard, or a New ticket email to spiceworks.

These macros create a text string representation of one or several selected messages in outlook. The string includes To,CC,and BCC with Names and email addresses. The string also lists Attachments.

One macro copies the text to the Clipboard.

The other macro copies the text into the body of a new email message addressed to the spiceworks email address (which you need to customize to your environment) and appends the Spiceworks #TicketsAnywhere command #accept. It also grabs the original attachments fromt he selected email(s) and attaches them to the new email.

####
This requires the "Microsoft Scripting Runtime" reference to be enabled in VBA.
###

Steps.
1. Enable the Developer Tab in the Ribbon.
2. Open VBA, Create a new model, Copy this code in and save.
3. Go to tools > references and enable the microsoft scripting agent.
4. Go to the Trust Center and ease up on the Macro security
5. Add macros as buttons on the quick launch toolbar
6. To use. select message and click button in the toolbar.

Source Code

This script has not been checked by Spiceworks. Please understand the risks before using it.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

' Declarations to use clipboard' http://msdn.microsoft.com/en-us/library/office/ff192913(v=office.15).aspxDeclareFunctionGlobalUnlockLib"kernel32"(ByValhMemAsLong)_AsLongDeclareFunctionGlobalLockLib"kernel32"(ByValhMemAsLong)_AsLongDeclareFunctionGlobalAllocLib"kernel32"(ByValwFlagsAsLong,_ByValdwBytesAsLong)AsLongDeclareFunctionCloseClipboardLib"User32"()AsLongDeclareFunctionOpenClipboardLib"User32"(ByValhwndAsLong)_AsLongDeclareFunctionEmptyClipboardLib"User32"()AsLongDeclareFunctionlstrcpyLib"kernel32"(ByVallpString1AsAny,_ByVallpString2AsAny)AsLongDeclareFunctionSetClipboardDataLib"User32"(ByValwFormat_AsLong,ByValhMemAsLong)AsLongPublicConstGHND=&H42PublicConstCF_TEXT=1PublicConstMAXSIZE=4096' Function to set Clipboard data' http://msdn.microsoft.com/en-us/library/office/ff192913(v=office.15).aspxFunctionClipBoard_SetData(MyStringAsString)DimhGlobalMemoryAsLong,lpGlobalMemoryAsLongDimhClipMemoryAsLong,XAsLong' Allocate moveable global memory.'-------------------------------------------hGlobalMemory=GlobalAlloc(GHND,Len(MyString)+1)' Lock the block to get a far pointer' to this memory.lpGlobalMemory=GlobalLock(hGlobalMemory)' Copy the string to this global memory.lpGlobalMemory=lstrcpy(lpGlobalMemory,MyString)' Unlock the memory.IfGlobalUnlock(hGlobalMemory)<>0ThenMsgBox"Could not unlock memory location. Copy aborted."GoToOutOfHere2EndIf' Open the Clipboard to copy data to.IfOpenClipboard(0&)=0ThenMsgBox"Could not open the Clipboard. Copy aborted."ExitFunctionEndIf' Clear the Clipboard.X=EmptyClipboard()' Copy the data to the Clipboard.hClipMemory=SetClipboardData(CF_TEXT,hGlobalMemory)OutOfHere2:IfCloseClipboard()=0ThenMsgBox"Could not close Clipboard."EndIfEndFunctionFunctionCopyMessage()DimoAppAsOutlook.ApplicationDimoExpAsOutlook.ExplorerDimoSelAsOutlook.SelectionDimoMailItemAsOutlook.MailItemDimRecipientAsOutlook.RecipientDimstrAsStringSetoApp=NewOutlook.ApplicationSetoExp=oApp.ActiveExplorerSetoSel=oExp.SelectionSetoMailItems=oSelstr=""ForEachoMailItemInoMailItemsIfoMailItems.Count>1Thenstr=str&vbCrLf&"###### Message ######"&vbCrLf&vbCrLfEndIfstr=str&_"From: "&_oMailItem.Sender.Name&_" ("&GetEmail(oMailItem.Sender)&") "&_vbCrLf&_"Sent: "&oMailItem.SentOnstr=str&vbCrLf&"To: "Recipients_To=Split(oMailItem.To,"; ")Fori=LBound(Recipients_To)ToUBound(Recipients_To)SetRecipient=oMailItem.Recipients.Item(Recipients_To(i))str=str&_Recipient.Name&_" ("&GetEmail(Recipient.AddressEntry,Recipient.DisplayType)&")"Ifi<UBound(Recipients_To)Thenstr=str&"; "EndIfNextIfNotoMailItem.CC=""Thenstr=str&vbCrLf&"CC: "Recipients_CC=Split(oMailItem.CC,"; ")Fori=LBound(Recipients_CC)ToUBound(Recipients_CC)SetRecipient=oMailItem.Recipients.Item(Recipients_CC(i))str=str&Recipient.Name&_" ("&GetEmail(Recipient.AddressEntry,Recipient.DisplayType)&")"Ifi<UBound(Recipients_CC)Thenstr=str&"; "EndIfNextEndIfIfNotoMailItem.BCC=""Thenstr=str&vbCrLf&"BCC: "Recipients_BCC=Split(oMailItem.BCC,"; ")Fori=LBound(Recipients_BCC)ToUBound(Recipients_BCC)SetRecipient=oMailItem.Recipients.Item(Recipients_BCC(i))str=str&Recipient.Name&_" ("&GetEmail(Recipient.AddressEntry,Recipient.DisplayType)&")"Ifi<UBound(Recipients_BCC)Thenstr=str&"; "EndIfNextEndIfstr=str&vbCrLf&_"Subject: "&oMailItem.Subject&vbCrLfIfNotoMailItem.Attachments.Count=0Thenstr=str&"Attachments: "ForEachAttachmentInoMailItem.Attachmentsstr=str&Attachment.FileNameIfAttachment.Index<oMailItem.Attachments.CountThenstr=str&"; "EndIfNextEndIfstr=str&vbCrLf&vbCrLf&_oMailItem.BodyNextCopyMessage=strEndFunctionFunctionGetEmail(oAddressEntryAsOutlook.AddressEntry,OptionalDisplayTypeAsOutlook.OlDisplayType=Outlook.OlDisplayType.olUser)IfoAddressEntry.Type="EX"ThenIfDisplayType=Outlook.OlDisplayType.olDistListThenGetEmail=oAddressEntry.GetExchangeDistributionList().PrimarySmtpAddressElseIfDisplayType=Outlook.OlDisplayType.olUserThenGetEmail=oAddressEntry.GetExchangeUser().PrimarySmtpAddressEndIfElseGetEmail=oAddressEntry.AddressEndIfEndFunctionSubCopyMessageToClipboard()ClipBoard_SetData(CopyMessage())EndSubSubNewTicketEmailFromMessage()DimoAppAsOutlook.ApplicationDimoNewMailItemAsOutlook.MailItemDimoRecAsOutlook.RecipientDimoExpAsOutlook.ExplorerDimoSelAsOutlook.SelectionDimfsoAsFileSystemObjectSetoApp=NewOutlook.ApplicationSetoNewMailItem=oApp.CreateItem(olMailItem)Setfso=NewFileSystemObjectSetoExp=oApp.ActiveExplorerSetoSel=oExp.SelectionSetoMailItems=oSelSetoRec=oNewMailItem.Recipients.Add("ticket@domain.com")oRec.Type=olTooNewMailItem.Subject=oMailItems.Item(1).Subjecttmp_folder_path=Environ("userprofile")&"\outlookvbatmp"IfNotfso.FolderExists(tmp_folder_path)Thenfso.CreateFoldertmp_folder_pathEndIfForEachoMailItemInoMailItemsForEachAttachmentInoMailItem.AttachmentsPath=tmp_folder_path&"\"&Attachment.FileNameAttachment.SaveAsFile(Path)oNewMailItem.Attachments.Add(Path)fso.DeleteFilePathNextNextfso.DeleteFoldertmp_folder_pathoNewMailItem.Body=CopyMessage()&vbCrLf&"#accept"ForEachoRecInoNewMailItem.RecipientsoRec.ResolveNextoNewMailItem.DisplayEndSub