Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #7  
Old 10-03-2014, 07:23 AM
madcar86 madcar86 is offline Save Filename based on Text Field Windows 7 64bit Save Filename based on Text Field Office 2013
Novice
Save Filename based on Text Field
 
Join Date: Sep 2014
Posts: 4
madcar86 is on a distinguished road
Default

I now get a error expected function or variable and it highlights saveas2. Could it be that it is an Active X button? I know this is getting annoying for you I appreciate the help.

Code:
Private Sub CommandButton1_Click()
    Dim oOutlookApp As Object
    Dim oItem As Object
    Dim olInsp As Object
    Dim strFname As String
    Dim wdDoc As Document
    Dim oRng As Range

        With ActiveDocument
            strFname = .SaveAs2(FileName:="C:\Users\" & Environ("Username") & "\Documents\" & _
             .SelectContentControlsByTitle("Title")(1).Range.Text & ".PDF", _
             FileFormat:=wdFormatPDF)
        End With
    
        On Error Resume Next
        'Get Outlook if it's running
        Set oOutlookApp = GetObject(, "Outlook.Application")
    
        'Outlook wasn't running, start it from code
        If Err <> 0 Then
            Set oOutlookApp = CreateObject("Outlook.Application")
        End If
        On Error GoTo 0
        'Create a new mailitem
        Set oItem = oOutlookApp.CreateItem(0)
    
        With oItem
            Set olInsp = .GetInspector
            Set wdDoc = olInsp.WordEditor
            Set oRng = wdDoc.Range
            oRng.Collapse 1
            oRng.Text = "This is the message body"
            .to = "someone@somewhere.com"
            .Subject = "This is the subject"
            .BodyFormat = 2
            .Attachments.Add strFname
            .Display
        End With
    
        'Clean up
        Set oItem = Nothing
        Set oOutlookApp = Nothing
        Set olInsp = Nothing
        Set wdDoc = Nothing
        Set oRng = Nothing
lbl_Exit:
        Exit Sub
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Save Filename based on Text Field How can I save a Word Document as a PDF file with a merged field filename? kp2009 Word VBA 5 08-27-2015 11:45 PM
Save Filename based on Text Field Auto update Filename field Oliver Beirne Word VBA 4 10-19-2012 03:33 AM
Macro to populate a text form field based on dropdown selection koloa Word 0 10-20-2011 11:52 AM
Save Filename based on Text Field Save Filename using Document Text Knawl Word 11 10-10-2011 03:00 AM
Save Filename based on Text Field Selecting merge field based on whether or not text is present amym Mail Merge 1 12-07-2010 05:14 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:38 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft