PDA

View Full Version : Printing Outlook Form Controls via Word



CruciasNZ
11-19-2013, 07:49 PM
Howdy all. I've been following advice from various threads on here (cannot link on new account, thread suffix for this forum-> showthread.php?48183-VBA-Send-Recurring-Task-In-Email) but I cannot seem to get it working. The overly simplfied version of what I am doing is as follows:

I have a Label in word called "projectName" who's caption is blank. I have a textbox in Outlook called "projectName". I want to hit the button on the form and send the value in the textbox to that label in word, and then print the word document. If someone could help me correct the line I've made obvious I would appreciate it (also if there's errors below it I'd appreciate the heads up). All I have is textboxes, checkboxes and comboboxes in the form.



Sub printButton_Click()
Set oWordApp = CreateObject("Word.Application")
Set FormPage = Item.GetInspector.ModifiedFormPages("Message")

If oWordApp Is Nothing Then
MsgBox "Couldn't start Word."
Else
MsgBox "Could Start Word."
Dim oWordApp
Dim oWordDoc
Dim bolPrintBackground

' Open a new document.
Set oDoc = oWordApp.Documents.Add("C:\Scratchpad\Survey_Request_Form_Print_Template.dotm")

'Set the first bookmark to the contact's full name.
'********** THIS LINE IS BORKED **********
oDoc.FormFields("projectName").Label = CStr(FormPage.Controls("projectName").Text)
'********** THIS LINE IS BORKED **********
 

' Get the current Word setting for background printing.
bolPrintBackground = oWordApp.Options.PrintBackground

' Turn background printing off.
oWordApp.Options.PrintBackground = False

 

' Print the Word document.
oDoc.PrintOut

' Restore previous setting.
oWordApp.Options.PrintBackground = bolPrintBackground

 
' Close and do not save changes to the document.

Const wdDoNotSaveChanges = 0

oDoc.Close wdDoNotSaveChanges

 

' Close the Word instance.
oWordApp.Quit

'Clean up.
Set oDoc = Nothing
Set oWordApp = Nothing

End If
End Sub

CruciasNZ
11-24-2013, 12:33 PM
Bump - could really do with help here. Been stalled out on this for a weekCheers guys