![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
Hello,
I have a custom form that auto populates a Word template. I do this to populate the subject field and it works: objDoc.MailEnvelope.Item.Subject = "Test" I'm trying to attach to it and it's not working. I'm trying this: objDoc.MailEnvelope.Item.Attachments = "C:\Test.doc" and this: objDoc.MailEnvelope.Item.Attachments.Add = "C:\Test.doc" and it's not working. Any help is much appriciated. Thanks, Joel |
Ads |
#2
|
|||
|
|||
![]()
That's strange, it should work. Could you show all of your code please?
-- Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Joel Allen" wrote: Hello, I have a custom form that auto populates a Word template. I do this to populate the subject field and it works: objDoc.MailEnvelope.Item.Subject = "Test" I'm trying to attach to it and it's not working. I'm trying this: objDoc.MailEnvelope.Item.Attachments = "C:\Test.doc" and this: objDoc.MailEnvelope.Item.Attachments.Add = "C:\Test.doc" and it's not working. Any help is much appriciated. Thanks, Joel |
#3
|
|||
|
|||
![]()
Yes, thanks for your help.
Sub CommandButton1_Click() Dim objDoc On Error Resume Next Set objDoc = GetWordDoc("\\tgps8\drawing$\Jobs\Task_Templates\L etter-Shop Drawing Xmit.dot") Call FillFields1(objDoc) objDoc.Application.Options.PrintBackground = True 'objDoc.PrintOut 'objDoc.Close wdDoNotSaveChanges objDoc.MailEnvelope.Item.To = Item.UserProperties("ContactEmail") objDoc.MailEnvelope.Item.Attachments = "C:\Test.doc" objDoc.MailEnvelope.Item.Subject = "#"+Item.UserProperties("JobNumber")+" "+Item.UserProperties("JobName")+" - PO# "+Item.UserProperties("CustomerPO") Call RestoreWord Set objDoc = Nothing End Sub Sub FillFields1(objDoc) On Error Resume Next Dim colFields Set colFields = objDoc.FormFields ' colFields("RequestDate").Result = Item.LastModificationTime colFields("CompanyName").Result = _ Item.UserProperties("CompanyName") colFields("MAStreet").Result = _ Item.UserProperties("MAStreet") colFields("MACity").Result = _ Item.UserProperties("MACity") colFields("MAState").Result = _ Item.UserProperties("MAState") colFields("MAZip").Result = _ Item.UserProperties("MAZip") colFields("MACountry").Result = _ Item.UserProperties("MACountry") colFields("ContactName").Result = _ Item.UserProperties("ContactName") colFields("ContactNameLast").Result = _ Item.UserProperties("ContactNameLast") colFields("ContactName2").Result = _ Item.UserProperties("ContactName") colFields("JobNumber").Result = _ Item.UserProperties("JobNumber") colFields("JobName").Result = _ Item.UserProperties("JobName") colFields("CustomerPO").Result = _ Item.UserProperties("CustomerPO") colFields("TwentyFivePercent").Result = _ Item.UserProperties("TwentyFivePercent") colFields("TwentyFivePercentRep").Result = _ Item.UserProperties("TwentyFivePercent") colFields("TwentyFivePercent3").Result = _ Item.UserProperties("TwentyFivePercent") colFields("TwentyFivePercent4").Result = _ Item.UserProperties("TwentyFivePercent") colFields("TwentyFivePercent5").Result = _ Item.UserProperties("TwentyFivePercent") colFields("ContactPhoneNumber").Result = _ Item.UserProperties("ContactPhoneNumber") colFields("ContactFaxNumber").Result = _ Item.UserProperties("ContactFaxNumber") Call SetPMValues colFields("PMPosition").Result = PMPosition colFields("PM").Result = PM colFields("PM2").Result = PM2 colFields("PMFAX").Result = PMFAX colFields("PMFAX2").Result = PMFAX2 colFields("PMFAX3").Result = PMFAX3 colFields("PMEXT").Result = PMEXT colFields("PMEXT2").Result = PMEXT2 colFields("PMEMAIL").Result = PMEMAIL 'objDoc.Bookmarks("Details").Range.InsertAfter Item.Body Set colFields = Nothing End Sub Private Function GetWordDoc(strTemplatePath) Dim objWord On Error Resume Next m_blnWeOpenedWord = False Set objWord = GetObject(, "Word.Application") If objWord Is Nothing Then Set objWord = CreateObject("Word.Application") m_blnWeOpenedWord = True End If m_blnWordPrintBackground = _ objWord.Options.PrintBackground If strTemplatePath = "" Then strTemplatePath = "\\tgps8\drawing$\Jobs\Task_Templates\Normal.d ot" End If Set GetWordDoc = objWord.Documents.Add(strTemplatePath) Set objWord = Nothing End Function Sub RestoreWord() Dim objWord On Error Resume Next Set objWord = GetObject(, "Word.Application") objWord.Options.PrintBackground = _ m_blnWordPrintBackground If m_blnWeOpenedWord Then objWord.Quit Else objWord.Visible = True End If Set objWord = Nothing End Sub "Eric Legault [MVP - Outlook]" wrote in message ... That's strange, it should work. Could you show all of your code please? -- Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Joel Allen" wrote: Hello, I have a custom form that auto populates a Word template. I do this to populate the subject field and it works: objDoc.MailEnvelope.Item.Subject = "Test" I'm trying to attach to it and it's not working. I'm trying this: objDoc.MailEnvelope.Item.Attachments = "C:\Test.doc" and this: objDoc.MailEnvelope.Item.Attachments.Add = "C:\Test.doc" and it's not working. Any help is much appriciated. Thanks, Joel |
#4
|
|||
|
|||
![]()
I neglected to mention that Attachments.Add("C:\MyFolder\MyFile.txt") is the
proper way to add an attachment. Try removing all the On Error Resume Next statements and see if you get a specific error at a specific point. -- Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Joel Allen" wrote: Yes, thanks for your help. Sub CommandButton1_Click() Dim objDoc On Error Resume Next Set objDoc = GetWordDoc("\\tgps8\drawing$\Jobs\Task_Templates\L etter-Shop Drawing Xmit.dot") Call FillFields1(objDoc) objDoc.Application.Options.PrintBackground = True 'objDoc.PrintOut 'objDoc.Close wdDoNotSaveChanges objDoc.MailEnvelope.Item.To = Item.UserProperties("ContactEmail") objDoc.MailEnvelope.Item.Attachments = "C:\Test.doc" objDoc.MailEnvelope.Item.Subject = "#"+Item.UserProperties("JobNumber")+" "+Item.UserProperties("JobName")+" - PO# "+Item.UserProperties("CustomerPO") Call RestoreWord Set objDoc = Nothing End Sub Sub FillFields1(objDoc) On Error Resume Next Dim colFields Set colFields = objDoc.FormFields ' colFields("RequestDate").Result = Item.LastModificationTime colFields("CompanyName").Result = _ Item.UserProperties("CompanyName") colFields("MAStreet").Result = _ Item.UserProperties("MAStreet") colFields("MACity").Result = _ Item.UserProperties("MACity") colFields("MAState").Result = _ Item.UserProperties("MAState") colFields("MAZip").Result = _ Item.UserProperties("MAZip") colFields("MACountry").Result = _ Item.UserProperties("MACountry") colFields("ContactName").Result = _ Item.UserProperties("ContactName") colFields("ContactNameLast").Result = _ Item.UserProperties("ContactNameLast") colFields("ContactName2").Result = _ Item.UserProperties("ContactName") colFields("JobNumber").Result = _ Item.UserProperties("JobNumber") colFields("JobName").Result = _ Item.UserProperties("JobName") colFields("CustomerPO").Result = _ Item.UserProperties("CustomerPO") colFields("TwentyFivePercent").Result = _ Item.UserProperties("TwentyFivePercent") colFields("TwentyFivePercentRep").Result = _ Item.UserProperties("TwentyFivePercent") colFields("TwentyFivePercent3").Result = _ Item.UserProperties("TwentyFivePercent") colFields("TwentyFivePercent4").Result = _ Item.UserProperties("TwentyFivePercent") colFields("TwentyFivePercent5").Result = _ Item.UserProperties("TwentyFivePercent") colFields("ContactPhoneNumber").Result = _ Item.UserProperties("ContactPhoneNumber") colFields("ContactFaxNumber").Result = _ Item.UserProperties("ContactFaxNumber") Call SetPMValues colFields("PMPosition").Result = PMPosition colFields("PM").Result = PM colFields("PM2").Result = PM2 colFields("PMFAX").Result = PMFAX colFields("PMFAX2").Result = PMFAX2 colFields("PMFAX3").Result = PMFAX3 colFields("PMEXT").Result = PMEXT colFields("PMEXT2").Result = PMEXT2 colFields("PMEMAIL").Result = PMEMAIL 'objDoc.Bookmarks("Details").Range.InsertAfter Item.Body Set colFields = Nothing End Sub Private Function GetWordDoc(strTemplatePath) Dim objWord On Error Resume Next m_blnWeOpenedWord = False Set objWord = GetObject(, "Word.Application") If objWord Is Nothing Then Set objWord = CreateObject("Word.Application") m_blnWeOpenedWord = True End If m_blnWordPrintBackground = _ objWord.Options.PrintBackground If strTemplatePath = "" Then strTemplatePath = "\\tgps8\drawing$\Jobs\Task_Templates\Normal.d ot" End If Set GetWordDoc = objWord.Documents.Add(strTemplatePath) Set objWord = Nothing End Function Sub RestoreWord() Dim objWord On Error Resume Next Set objWord = GetObject(, "Word.Application") objWord.Options.PrintBackground = _ m_blnWordPrintBackground If m_blnWeOpenedWord Then objWord.Quit Else objWord.Visible = True End If Set objWord = Nothing End Sub "Eric Legault [MVP - Outlook]" wrote in message ... That's strange, it should work. Could you show all of your code please? -- Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Joel Allen" wrote: Hello, I have a custom form that auto populates a Word template. I do this to populate the subject field and it works: objDoc.MailEnvelope.Item.Subject = "Test" I'm trying to attach to it and it's not working. I'm trying this: objDoc.MailEnvelope.Item.Attachments = "C:\Test.doc" and this: objDoc.MailEnvelope.Item.Attachments.Add = "C:\Test.doc" and it's not working. Any help is much appriciated. Thanks, Joel |
#5
|
|||
|
|||
![]()
Thanks Eric, that worked!
"Eric Legault [MVP - Outlook]" wrote in message ... I neglected to mention that Attachments.Add("C:\MyFolder\MyFile.txt") is the proper way to add an attachment. Try removing all the On Error Resume Next statements and see if you get a specific error at a specific point. -- Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Joel Allen" wrote: Yes, thanks for your help. Sub CommandButton1_Click() Dim objDoc On Error Resume Next Set objDoc = GetWordDoc("\\tgps8\drawing$\Jobs\Task_Templates\L etter-Shop Drawing Xmit.dot") Call FillFields1(objDoc) objDoc.Application.Options.PrintBackground = True 'objDoc.PrintOut 'objDoc.Close wdDoNotSaveChanges objDoc.MailEnvelope.Item.To = Item.UserProperties("ContactEmail") objDoc.MailEnvelope.Item.Attachments = "C:\Test.doc" objDoc.MailEnvelope.Item.Subject = "#"+Item.UserProperties("JobNumber")+" "+Item.UserProperties("JobName")+" - PO# "+Item.UserProperties("CustomerPO") Call RestoreWord Set objDoc = Nothing End Sub Sub FillFields1(objDoc) On Error Resume Next Dim colFields Set colFields = objDoc.FormFields ' colFields("RequestDate").Result = Item.LastModificationTime colFields("CompanyName").Result = _ Item.UserProperties("CompanyName") colFields("MAStreet").Result = _ Item.UserProperties("MAStreet") colFields("MACity").Result = _ Item.UserProperties("MACity") colFields("MAState").Result = _ Item.UserProperties("MAState") colFields("MAZip").Result = _ Item.UserProperties("MAZip") colFields("MACountry").Result = _ Item.UserProperties("MACountry") colFields("ContactName").Result = _ Item.UserProperties("ContactName") colFields("ContactNameLast").Result = _ Item.UserProperties("ContactNameLast") colFields("ContactName2").Result = _ Item.UserProperties("ContactName") colFields("JobNumber").Result = _ Item.UserProperties("JobNumber") colFields("JobName").Result = _ Item.UserProperties("JobName") colFields("CustomerPO").Result = _ Item.UserProperties("CustomerPO") colFields("TwentyFivePercent").Result = _ Item.UserProperties("TwentyFivePercent") colFields("TwentyFivePercentRep").Result = _ Item.UserProperties("TwentyFivePercent") colFields("TwentyFivePercent3").Result = _ Item.UserProperties("TwentyFivePercent") colFields("TwentyFivePercent4").Result = _ Item.UserProperties("TwentyFivePercent") colFields("TwentyFivePercent5").Result = _ Item.UserProperties("TwentyFivePercent") colFields("ContactPhoneNumber").Result = _ Item.UserProperties("ContactPhoneNumber") colFields("ContactFaxNumber").Result = _ Item.UserProperties("ContactFaxNumber") Call SetPMValues colFields("PMPosition").Result = PMPosition colFields("PM").Result = PM colFields("PM2").Result = PM2 colFields("PMFAX").Result = PMFAX colFields("PMFAX2").Result = PMFAX2 colFields("PMFAX3").Result = PMFAX3 colFields("PMEXT").Result = PMEXT colFields("PMEXT2").Result = PMEXT2 colFields("PMEMAIL").Result = PMEMAIL 'objDoc.Bookmarks("Details").Range.InsertAfter Item.Body Set colFields = Nothing End Sub Private Function GetWordDoc(strTemplatePath) Dim objWord On Error Resume Next m_blnWeOpenedWord = False Set objWord = GetObject(, "Word.Application") If objWord Is Nothing Then Set objWord = CreateObject("Word.Application") m_blnWeOpenedWord = True End If m_blnWordPrintBackground = _ objWord.Options.PrintBackground If strTemplatePath = "" Then strTemplatePath = "\\tgps8\drawing$\Jobs\Task_Templates\Normal.d ot" End If Set GetWordDoc = objWord.Documents.Add(strTemplatePath) Set objWord = Nothing End Function Sub RestoreWord() Dim objWord On Error Resume Next Set objWord = GetObject(, "Word.Application") objWord.Options.PrintBackground = _ m_blnWordPrintBackground If m_blnWeOpenedWord Then objWord.Quit Else objWord.Visible = True End If Set objWord = Nothing End Sub "Eric Legault [MVP - Outlook]" wrote in message ... That's strange, it should work. Could you show all of your code please? -- Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Joel Allen" wrote: Hello, I have a custom form that auto populates a Word template. I do this to populate the subject field and it works: objDoc.MailEnvelope.Item.Subject = "Test" I'm trying to attach to it and it's not working. I'm trying this: objDoc.MailEnvelope.Item.Attachments = "C:\Test.doc" and this: objDoc.MailEnvelope.Item.Attachments.Add = "C:\Test.doc" and it's not working. Any help is much appriciated. Thanks, Joel |
#6
|
|||
|
|||
![]()
Great! My bad though - I thought you tried that already, but after rereading
your first post I see now it was a syntax error. -- Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Joel Allen" wrote: Thanks Eric, that worked! "Eric Legault [MVP - Outlook]" wrote in message ... I neglected to mention that Attachments.Add("C:\MyFolder\MyFile.txt") is the proper way to add an attachment. Try removing all the On Error Resume Next statements and see if you get a specific error at a specific point. -- Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Joel Allen" wrote: Yes, thanks for your help. Sub CommandButton1_Click() Dim objDoc On Error Resume Next Set objDoc = GetWordDoc("\\tgps8\drawing$\Jobs\Task_Templates\L etter-Shop Drawing Xmit.dot") Call FillFields1(objDoc) objDoc.Application.Options.PrintBackground = True 'objDoc.PrintOut 'objDoc.Close wdDoNotSaveChanges objDoc.MailEnvelope.Item.To = Item.UserProperties("ContactEmail") objDoc.MailEnvelope.Item.Attachments = "C:\Test.doc" objDoc.MailEnvelope.Item.Subject = "#"+Item.UserProperties("JobNumber")+" "+Item.UserProperties("JobName")+" - PO# "+Item.UserProperties("CustomerPO") Call RestoreWord Set objDoc = Nothing End Sub Sub FillFields1(objDoc) On Error Resume Next Dim colFields Set colFields = objDoc.FormFields ' colFields("RequestDate").Result = Item.LastModificationTime colFields("CompanyName").Result = _ Item.UserProperties("CompanyName") colFields("MAStreet").Result = _ Item.UserProperties("MAStreet") colFields("MACity").Result = _ Item.UserProperties("MACity") colFields("MAState").Result = _ Item.UserProperties("MAState") colFields("MAZip").Result = _ Item.UserProperties("MAZip") colFields("MACountry").Result = _ Item.UserProperties("MACountry") colFields("ContactName").Result = _ Item.UserProperties("ContactName") colFields("ContactNameLast").Result = _ Item.UserProperties("ContactNameLast") colFields("ContactName2").Result = _ Item.UserProperties("ContactName") colFields("JobNumber").Result = _ Item.UserProperties("JobNumber") colFields("JobName").Result = _ Item.UserProperties("JobName") colFields("CustomerPO").Result = _ Item.UserProperties("CustomerPO") colFields("TwentyFivePercent").Result = _ Item.UserProperties("TwentyFivePercent") colFields("TwentyFivePercentRep").Result = _ Item.UserProperties("TwentyFivePercent") colFields("TwentyFivePercent3").Result = _ Item.UserProperties("TwentyFivePercent") colFields("TwentyFivePercent4").Result = _ Item.UserProperties("TwentyFivePercent") colFields("TwentyFivePercent5").Result = _ Item.UserProperties("TwentyFivePercent") colFields("ContactPhoneNumber").Result = _ Item.UserProperties("ContactPhoneNumber") colFields("ContactFaxNumber").Result = _ Item.UserProperties("ContactFaxNumber") Call SetPMValues colFields("PMPosition").Result = PMPosition colFields("PM").Result = PM colFields("PM2").Result = PM2 colFields("PMFAX").Result = PMFAX colFields("PMFAX2").Result = PMFAX2 colFields("PMFAX3").Result = PMFAX3 colFields("PMEXT").Result = PMEXT colFields("PMEXT2").Result = PMEXT2 colFields("PMEMAIL").Result = PMEMAIL 'objDoc.Bookmarks("Details").Range.InsertAfter Item.Body Set colFields = Nothing End Sub Private Function GetWordDoc(strTemplatePath) Dim objWord On Error Resume Next m_blnWeOpenedWord = False Set objWord = GetObject(, "Word.Application") If objWord Is Nothing Then Set objWord = CreateObject("Word.Application") m_blnWeOpenedWord = True End If m_blnWordPrintBackground = _ objWord.Options.PrintBackground If strTemplatePath = "" Then strTemplatePath = "\\tgps8\drawing$\Jobs\Task_Templates\Normal.d ot" End If Set GetWordDoc = objWord.Documents.Add(strTemplatePath) Set objWord = Nothing End Function Sub RestoreWord() Dim objWord On Error Resume Next Set objWord = GetObject(, "Word.Application") objWord.Options.PrintBackground = _ m_blnWordPrintBackground If m_blnWeOpenedWord Then objWord.Quit Else objWord.Visible = True End If Set objWord = Nothing End Sub "Eric Legault [MVP - Outlook]" wrote in message ... That's strange, it should work. Could you show all of your code please? -- Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Joel Allen" wrote: Hello, I have a custom form that auto populates a Word template. I do this to populate the subject field and it works: objDoc.MailEnvelope.Item.Subject = "Test" I'm trying to attach to it and it's not working. I'm trying this: objDoc.MailEnvelope.Item.Attachments = "C:\Test.doc" and this: objDoc.MailEnvelope.Item.Attachments.Add = "C:\Test.doc" and it's not working. Any help is much appriciated. Thanks, Joel |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Code error in custom contact form - Outlook 2003 | [email protected] | Outlook - Using Contacts | 1 | April 4th 07 02:15 PM |
How to run the custom Appointment form code ? | DP | Outlook - Using Forms | 3 | March 20th 07 03:48 PM |
How to access a custom control in an outlook form from my VBA code? | MeAgin | Outlook and VBA | 1 | January 23rd 07 06:39 AM |
Evault custom form & preview pane code | [email protected] | Outlook and VBA | 3 | August 31st 06 07:51 PM |
Code to set Flag Status to complete on custom form | ICT User | Outlook - Using Forms | 3 | March 28th 06 12:59 AM |