2016-08-11 1 views
1

Word Doc를 pdf로 변환하고 작성한 Outlook 전자 메일의 일부로 첨부 파일로 보내고 싶습니다.워드 문서를 pdf로 변환하고 Outlook에서 첨부 파일로 보내십시오.

파일을 열려고 시도 할 때 파일 형식을 변경하고 첨부 한 SaveAs2 행의 끝에 ".pdf"를 추가하려고 시도했지만 표시되지 않고 다음 메시지가 나타납니다. 첨부 파일로 보낼 때 파일에 코드가 없습니다.

모든 의견을 크게 기뻐할 것입니다. 감사합니다

Private Sub emailbutton_Click() 
     'No-option email sending 
     Dim OL    As Object 
     Dim EmailItem  As Object 
     Dim Doc    As Document 

     Application.ScreenUpdating = False 
     Set OL = CreateObject("Outlook.Application") 
     Set EmailItem = OL.CreateItem(olMailItem) 
     Set Doc = ActiveDocument 

     If VName.Value = "" Then 
      Doc.SaveAs ("Quotation_Blank 2016") 
     Else 
      Doc.SaveAs2 ("QFORM" & "_" & JNumber.Value & "_" & VName.Value) 

     End If 

     With EmailItem 
     .Display 
     End With 
    '  Signature = EmailItem.body 


     With EmailItem 
      .Subject = "QFORM" & "_" & JNumber.Value & "_" & VName.Value 

      'HTMLbody 
      msg = "<b><font face=""Times New Roman"" size=""4"" color=""blue"">INTEGRATED ASSEMBLY </font></b><br>" _ 
      & " 1200 Woodruff Rd.<br>" _ 
      & " Suite A12<br>" _ 
      & " Greenville, SC 29607<br><br>" _ 
      & "We have recently released subject project, which will contain assemblies to be outsourced. You have been selected to build these assemblies according to the attachment. <br><br>" _ 
      & "As part of this process, please review the quotation form attached and indicate your acceptance. If adjustments and-or corrections are required, please feel free to contact us for quick resolution. <br><br>" _ 
      & "<b><font face=""Times New Roman"" size=""4"" color=""Red"">NOTE: </font></b>" _ 
      & "The information on attached quotation form is not a contract and only an estimate of predetermined costs per hourly rate for outsource assemblies. <br><br>" _ 
      & "*******For your records you may wish to print out the completed quote form. <br><br>" _ 
      & "Thank you, <br><br>" _ 
      & "<b>HARTNESS INTERNATIONAL </b><br>" _ 
      & "H1 Production Control <br>" _ 
      & vbNewLine & Signature 

      .HTMLBody = msg & .HTMLBody 

      If VName.Value = "INTEGRATED ASSEMBLY" Then 
       .To = "Email1.com;" 
       .CC = "Email2.com;" & "Email3.com;" 
       .Importance = olImportanceNormal 'Or olImportanceHigh Or   olImportanceLow 
       .Attachments.Add Doc.FullName 
       .Display 
      ElseIf VName.Value = "LEWALLEN" Then 
       .To = "Email1.com;" 
       .CC = "Email2.com;" & "Email3.com;" 
       .Importance = olImportanceNormal 'Or olImportanceHigh Or   olImportanceLow 
       .Attachments.Add Doc.FullName 
       .Display 

      End If 
     End With 




     Application.ScreenUpdating = True 

     Set Doc = Nothing 
     Set OL = Nothing 
     Set EmailItem = Nothing 

    End Sub 

답변

1

당신의 saveAs2을 변화를 지정할 수 있습니다 이 방법. 당신이 t이 필요하면

If VName.Value = "" Then 
    Doc.SaveAs ("Quotation_Blank 2016") 
Else 
    Doc.ExportAsFixedFormat OutputFileName:="QFORM" & "_" & JNumber.Value , _ 
    ExportFormat:=wdExportFormatPDF 
End If 

편집

는 & 추가 첨부 파일

If VName.Value = "" Then 
    Doc.SaveAs ("Quotation_Blank 2016") 
Else 
    Path = "C:\Temp\" 
    FileName = "QFORM" & "_" & JNumber.Value & "_" & VName.Value 
    Doc.ExportAsFixedFormat OutputFileName:=Path & FileName, _ 
    ExportFormat:=wdExportFormatPDF 
End If 

그리고 Attahcment

 .Attachments.Add Path & FileName & ".pdf" 
+0

코드가 필요한 것처럼 보이지만 현재 폴더에 저장하기위한 경로를 만드는 방법과이 코드의 첨부 파일로 추가하는 방법을 생각합니다. 현재 .Attachment.Add Doc.FullName을 사용하고 있는데, 여전히 pdf 대신 word 파일을 가져옵니다. –

+0

@ReyTaino 업데이트 된 답변보기 – 0m3r

+1

좋은 전화 @ Om3r - Path를 Const로 만들어 약간 조정해야했습니다. "Compile Error - 현재 경로가있는 읽기 전용 속성에 할당 할 수 없습니다." . 도와 줘서 고마워. –

2

SaveAs2하면 화일 형식

https://msdn.microsoft.com/en-us/library/office/ff836084.aspx

expression .SaveAs2(FileName, FileFormat, LockComments, Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter, Encoding, InsertLineBreaks, AllowSubstitutions, LineEnding, AddBiDiMarks, CompatibilityMode)

https://msdn.microsoft.com/en-us/library/office/ff839952.aspx

화일 형식이 wdFormatPDF 또는 17

0

같다 경로를 사용하려면 여러 개의 Word 파일을 TXT, RTF, HTML 또는 PDF와 같은 다른 형식으로 변환하려면 아래 스크립트를 실행하십시오.

Option Explicit On 

Sub ChangeDocsToTxtOrRTFOrHTML() 
    'with export to PDF in Word 2007 
    Dim fs As Object 
    Dim oFolder As Object 
    Dim tFolder As Object 
    Dim oFile As Object 
    Dim strDocName As String 
    Dim intPos As Integer 
    Dim locFolder As String 
    Dim fileType As String 
    On Error Resume Next 

    locFolder = InputBox("Enter the folder path to DOCs", "File Conversion", "C:\Users\your_path_here\") 
    Select Case Application.Version 
     Case Is < 12 
      Do 
       fileType = UCase(InputBox("Change DOC to TXT, RTF, HTML", "File Conversion", "TXT")) 
      Loop Until (fileType = "TXT" Or fileType = "RTF" Or fileType = "HTML") 
     Case Is >= 12 
      Do 
       fileType = UCase(InputBox("Change DOC to TXT, RTF, HTML or PDF(2007+ only)", "File Conversion", "TXT")) 
      Loop Until (fileType = "TXT" Or fileType = "RTF" Or fileType = "HTML" Or fileType = "PDF") 
    End Select 

    Application.ScreenUpdating = False 
    Set fs = CreateObject("Scripting.FileSystemObject") 
    Set oFolder = fs.GetFolder(locFolder) 
    Set tFolder = fs.CreateFolder(locFolder & "Converted") 
    Set tFolder = fs.GetFolder(locFolder & "Converted") 

    For Each oFile In oFolder.Files 
     Dim d As Document 
     Set d = Application.Documents.Open(oFile.Path) 
     strDocName = ActiveDocument.Name 
     intPos = InStrRev(strDocName, ".") 
     strDocName = Left(strDocName, intPos - 1) 
     ChangeFileOpenDirectory tFolder 
     Select Case fileType 
      Case Is = "TXT" 
       strDocName = strDocName & ".txt" 
       ActiveDocument.SaveAs FileName:=strDocName, FileFormat:=wdFormatText 
     Case Is = "RTF" 
       strDocName = strDocName & ".rtf" 
       ActiveDocument.SaveAs FileName:=strDocName, FileFormat:=wdFormatRTF 
     Case Is = "HTML" 
       strDocName = strDocName & ".html" 
       ActiveDocument.SaveAs FileName:=strDocName, FileFormat:=wdFormatFilteredHTML 
     Case Is = "PDF" 
       strDocName = strDocName & ".pdf" 
       ActiveDocument.ExportAsFixedFormat OutputFileName:=strDocName, ExportFormat:=wdExportFormatPDF 
     End Select 
     d.Close 
     ChangeFileOpenDirectory oFolder 
    Next oFile 
    Application.ScreenUpdating = True 

End Sub 

결과는 방금 생성 한 폴더와 방금 변환 한 문서가 들어있는 폴더에 저장됩니다.