Consulting

Results 1 to 2 of 2

Thread: Printing Outlook Form Controls via Word

  1. #1

    Printing Outlook Form Controls via Word

    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

  2. #2
    Bump - could really do with help here. Been stalled out on this for a weekCheers guys

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •