ä½ å¥½
éè¿è°ç¨ wordçå®åå¯ä»¥æ²çº¿å®ç°è¿æ ·çåè½
è¡ä¹±ååºæ¥ç代ç ä¸è¿è°è¯ä»¥å·²ç»éè¿ å享ç»å¤§å®¶ ï¼ä¸è¦è´»ç¬å¤§æ¹å¦
Public wdApp As Word.Application
Public wdAppTem As Word.Application
Public Mail_Doc As String
Public Mail_Text
Public Mail_Counter As Integer
Public ReportDate_Temp As Date
Public Sent_Date As String
Public Sent_Date_Temp As String
Public Report_Flag As String
Public Report_Subject As String
Public Sub Open_Word_OutLook()
.......
Work_Path = ThisWorkbook.Path
Mail_Doc = Work_Path & "\" & "Mailok.doc"
Set wdApp = New Word.Application
With wdApp
.Documents.Open Filename:=Mail_Doc
.Visible = True
.ActiveWindow.EnvelopeVisible = False
End With
'æå¼word ç¼è¾word
wdApp.Selection.WholeStory
wdApp.Selection.Delete
'#####################################################################################
For Mail_Counter = 1 To 18
Mail_Text = ThisWorkbook.Sheets("Mail").Range("A" & Mail_Counter).Value
With wdApp
.Documents.Open Filename:=Mail_Doc
.Visible = True
With .Selection
.EndKey unit:=wdStory
.Text = Mail_Text
.EndKey unit:=wdLine
.TypeParagraph
End With
End With
Next Mail_Counter
'Finish Item 1 to 5
'#####################################################################################
Sheets("Report").Select
ThisWorkbook.Sheets("Report").Range(Cells(39, 1), Cells(51, 6)).Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Pictures.Paste.Select
Application.CutCopyMode = False
Selection.Cut
With wdApp
With .Selection
.EndKey unit:=wdStory
.Paste
.EndKey unit:=wdLine
.TypeParagraph
.TypeParagraph
End With
End With
'Finish Paste Equipment Status PIC
'#####################################################################################
Sheets("Mail").Select
Mail_Text = ThisWorkbook.Sheets("Mail").Range("A19").Value
With wdApp
With .Selection
.EndKey unit:=wdStory
.Text = Mail_Text
.EndKey unit:=wdLine
.TypeParagraph
.TypeParagraph
End With
End With
'Finish paste "ATE down Time & HST Availability"
Sheets("Report").Select
ThisWorkbook.Sheets("Report").Range(Cells(15, 1), Cells(21, 4)).Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Pictures.Paste.Select
Application.CutCopyMode = False
Selection.Cut
With wdApp
With .Selection
.EndKey unit:=wdStory
.Paste
.EndKey unit:=wdLine
.TypeParagraph
.TypeParagraph
End With
End With
'Finish Paste ATE down Time & HST Availability PIC
...........
...........
...........
Sheets("Mail").Select
ActiveSheet.Shapes("Picture 1").Select
Application.CutCopyMode = False
Selection.Copy
With wdApp
With .Selection
.EndKey unit:=wdStory
.Paste
.EndKey unit:=wdLine
End With
End With
'#####################################################################################
With wdApp
.ActiveDocument.Save
End With
'ç¼è¾word ç»æ
wdApp.Run "Create_Mail"
'è°ç¨word å® å°æ£æå建é®ä»¶ è³äºæ é¢æ¶ä»¶äººä¹ç±»å¨word vba ä¸å®æ
AppActivate "Microsoft word"
Do Until wdApp.ActiveWindow.EnvelopeVisible = False
On Error GoTo 1
Loop
With wdApp
' .ActiveDocument.Close
.Quit
End With
Set wdApp = Nothing
GoTo 3
1: Set wdApp = Nothing
GoTo 2
2: MsgBox "You have not sent the mail!!!" & Chr(10) & "The Word Appliction have not close correctly!!!"
3: Sheets("Report").Select
End Sub
温馨提示:答案为网友推荐,仅供参考