H
Himselff
Hi guys,
Im developing a lil add-in that is goiing to allow the user by a button
click to auto print PDF doc which are attach to hes emails, i think the
things is to simple cause its not working at all, hope u guys can gimme a
hand , heres the code,
Public Sub OnStartupComplete(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnStartupComplete
On Error Resume Next
Dim oCommandBars As CommandBars
Dim oStandardBar As CommandBar
' Set up a custom button on the "Standard" command bar.
oCommandBars = applicationObject.CommandBars
If oCommandBars Is Nothing Then
' Outlook has the CommandBars collection on the Explorer object.
oCommandBars = applicationObject.ActiveExplorer.CommandBars
End If
oStandardBar = oCommandBars.Item("Standard")
If oStandardBar Is Nothing Then
' Access names its main toolbar Database.
oStandardBar = oCommandBars.Item("Database")
End If
' In case the button was not deleted, use the exiting one.
MyButton = oStandardBar.Controls.Item("Polyform Auto-print")
If MyButton Is Nothing Then
MyButton = oStandardBar.Controls.Add(1)
With MyButton
.Caption = "Polyform Auto-Print"
.Style = MsoButtonStyle.msoButtonCaption
' The following items are optional, but recommended.
' The Tag property lets you quickly find the control
' and helps MSO keep track of it when more than
' one application window is visible. The property is required
' by some Office applications and should be provided.
.Tag = "Polyform Auto-print"
' The OnAction property is optional but recommended.
' It should be set to the ProgID of the add-in, so that if
' the add-in is not loaded when a user clicks the button,
' MSO loads the add-in automatically and then raises
' the Click event for the add-in to handle.
.OnAction = "!<MyCOMAddin.Connect>"
.Visible = True
End With
End If
MsgBox("button load")
oStandardBar = Nothing
oCommandBars = Nothing
End Sub
Private Sub MyButton_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Handles MyButton.Click
Dim myOutlook As Outlook.Application = New Outlook.Application
Dim myNs 'As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myMessage As Object
Dim pathName As String
Dim myAttachement As Outlook.Attachment
Dim items As Outlook.Items
myNs = myOutlook.GetNamespace("MAPI")
myFolder = myNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
items = myFolder.Items
MsgBox("variable setter")
Dim i As Integer
Dim oMsg As Outlook.MailItem
Dim attch, monExt, maLongueur
For i = 1 To items.Count
oMsg = items.Item(i)
If oMsg.Attachments.Count > 0 Then
oMsg.Attachments.Item(i).SaveAsFile("c:\travail\temp\attachements\" &
oMsg.Attachments.Item(i).FileName)
maLongueur = Len(oMsg.Attachments.Item(i).FileName)
monExt = Mid(oMsg.Attachments.Item(i).FileName, maLongueur - 2, 3)
MsgBox("Entre dans le case " & maLongueur & " " & monExt)
Select Case monExt
Case "pdf"
Process.Start("c:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe",
"/p/h ""C:\travail\temp\attachements\" & oMsg.Attachments.Item(i).FileName &
"")
End Select
MsgBox(oMsg.Attachments.Item(i).FileName)
End If
Next i
myOutlook = Nothing
myNs = Nothing
myFolder = Nothing
oMsg = Nothing
items = Nothing
MsgBox("Tout les commandes ont été imprimé correctement !")
End Sub
As u can see its very basic, add button, and when button is clicked and
thats it , ive generate all this trough add-in wizard of visual studio dot
net !
thanks in advance for the help !
Him
Im developing a lil add-in that is goiing to allow the user by a button
click to auto print PDF doc which are attach to hes emails, i think the
things is to simple cause its not working at all, hope u guys can gimme a
hand , heres the code,
Public Sub OnStartupComplete(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnStartupComplete
On Error Resume Next
Dim oCommandBars As CommandBars
Dim oStandardBar As CommandBar
' Set up a custom button on the "Standard" command bar.
oCommandBars = applicationObject.CommandBars
If oCommandBars Is Nothing Then
' Outlook has the CommandBars collection on the Explorer object.
oCommandBars = applicationObject.ActiveExplorer.CommandBars
End If
oStandardBar = oCommandBars.Item("Standard")
If oStandardBar Is Nothing Then
' Access names its main toolbar Database.
oStandardBar = oCommandBars.Item("Database")
End If
' In case the button was not deleted, use the exiting one.
MyButton = oStandardBar.Controls.Item("Polyform Auto-print")
If MyButton Is Nothing Then
MyButton = oStandardBar.Controls.Add(1)
With MyButton
.Caption = "Polyform Auto-Print"
.Style = MsoButtonStyle.msoButtonCaption
' The following items are optional, but recommended.
' The Tag property lets you quickly find the control
' and helps MSO keep track of it when more than
' one application window is visible. The property is required
' by some Office applications and should be provided.
.Tag = "Polyform Auto-print"
' The OnAction property is optional but recommended.
' It should be set to the ProgID of the add-in, so that if
' the add-in is not loaded when a user clicks the button,
' MSO loads the add-in automatically and then raises
' the Click event for the add-in to handle.
.OnAction = "!<MyCOMAddin.Connect>"
.Visible = True
End With
End If
MsgBox("button load")
oStandardBar = Nothing
oCommandBars = Nothing
End Sub
Private Sub MyButton_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Handles MyButton.Click
Dim myOutlook As Outlook.Application = New Outlook.Application
Dim myNs 'As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myMessage As Object
Dim pathName As String
Dim myAttachement As Outlook.Attachment
Dim items As Outlook.Items
myNs = myOutlook.GetNamespace("MAPI")
myFolder = myNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
items = myFolder.Items
MsgBox("variable setter")
Dim i As Integer
Dim oMsg As Outlook.MailItem
Dim attch, monExt, maLongueur
For i = 1 To items.Count
oMsg = items.Item(i)
If oMsg.Attachments.Count > 0 Then
oMsg.Attachments.Item(i).SaveAsFile("c:\travail\temp\attachements\" &
oMsg.Attachments.Item(i).FileName)
maLongueur = Len(oMsg.Attachments.Item(i).FileName)
monExt = Mid(oMsg.Attachments.Item(i).FileName, maLongueur - 2, 3)
MsgBox("Entre dans le case " & maLongueur & " " & monExt)
Select Case monExt
Case "pdf"
Process.Start("c:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe",
"/p/h ""C:\travail\temp\attachements\" & oMsg.Attachments.Item(i).FileName &
"")
End Select
MsgBox(oMsg.Attachments.Item(i).FileName)
End If
Next i
myOutlook = Nothing
myNs = Nothing
myFolder = Nothing
oMsg = Nothing
items = Nothing
MsgBox("Tout les commandes ont été imprimé correctement !")
End Sub
As u can see its very basic, add button, and when button is clicked and
thats it , ive generate all this trough add-in wizard of visual studio dot
net !
thanks in advance for the help !
Him