- ©«¤l
- 129
- ¥DÃD
- 25
- ºëµØ
- 0
- ¿n¤À
- 159
- ÂI¦W
- 0
- §@·~¨t²Î
- win7
- ³nÅ骩¥»
- office2010
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2011-12-24
- ³Ì«áµn¿ý
- 2022-12-12
|
[µo°Ý] µ{¦¡F8¥i¥HF5´N·í¾÷¡A¥H¤ÎÃö³¬WORD.EXE
¥»©«³Ì«á¥Ñ iceandy6150 ©ó 2020-3-31 23:13 ½s¿è
¤j®a¦n¡A§Ú¼g¤F¤@Ó«ö¶s¡A«ö¤U¥h¤§«á¡A¥Dn¥\¯à¬O¶}±Ò¤@ÓWORDÀÉ
µM«á¶i¦æ¦X¨Ö¦C¦L¡A¨Ã¦X¨Ö¦C¦L¨ì·sÀÉ®×
µ¥¨Ï¥ÎªÌ¦C¦L«á¡AÃö±¼·sÀɮ׸òìÀÉ®×
(³oÃ䥻¨Ó·Qn¼g¦¨¡A·sÀÉ®×·|¦Û°Ê¦C¦L¡AµM«áÃö±¼©Ò¦³WORDÀÉ)
(¦ý¬O©È¨Ï¥ÎªÌªº¦Lªí¾÷¥i¯à¤£ºÉ¬Û¦P¡A¦]¦¹§@½})
«e±·|¥ýÀˬd¬O§_¤w¸g¶}±ÒWORDÀÉ
¦³¶}´N¸ß°Ý¬O§_Ãö±¼WORD¡A©ÎªÌ¤£¦sÀɱj¨îÃö³¬
°ÝÃD¦b¡A¨C¤@¦¸¨Ï¥ÎªÌ¦C¦L«á¡AÃö±¼WORD·sÀɮ׸òìÀɮ׫á
¨ä¹ê¡i¤u§@ºÞ²zû¡j¸Ì±¡AWORD.EXE³oÓµ{§ÇÁÙ¬O¦s¦b
µM«á¡i¥ýÀˬd¬O§_¤w¸g¶}±ÒWORDÀÉ¡j³oÃä¡A¦pªGF8³v¨B°õ¦æ¡A¬O¨S°ÝÃDªº
¦pªGª½±µ«ö¤U«ö¶s°õ¦æ¡A´N·|¥d¦í(F5ª½±µ°õ¦æ´N·|¥d¦í)
¸Ñ¨M¿ìªk¬O¥h¡i¤u§@ºÞ²zû¡j¸Ì±¡A§âWORD.EXE³oÓµ{§ÇÃö±¼¡A¤~¯à¥¿±`¶]- Private Sub CommandButton2_Click()
- '====°»´ú¬O§_¦³¶}±Ò¤¤ªºWORDÀÉ¡A¨Ã¿ï«h¬O§_¦sÀÉÃö³¬====
- Dim WordApp As Object, Doc As Object
- Dim box
- On Error GoTo Skip '³]¸m¥X¿ù¸õÂà¦ì¸m
- Set WordApp = GetObject(, "word.application") 'Àò¨ú²Ä¤@Óword¶iµ{
- Do While Not WordApp Is Nothing '¦pªG¦¨¥\Àò¨ú¶iµ{,«h¶i¤J°j°é¾Þ§@
- With WordApp
- If .Documents.Count > 0 Then '¦pªG¶iµ{¤¤¦³¥´¶}ªº¤åÀÉ
- MsgBox ("°»´ú¨ì¦³©|¥¼Ãö³¬ªºWORDÀÉ®×")
- box = MsgBox("±znÂ÷¶}¥»µ{¦¡¡A¥ý±NWORDÀÉ®×Ãö³¬?" + Chr(13) + "¡i¬O¡jÂ÷¶}¥»µ{¦¡" + Chr(13) + "¡i§_¡j¤£¦sÀɪ½±µÃö³¬WORD", 4, "«n°T®§")
- If box = 6 Then
- Exit Sub
- Else
- For Each Doc In .Documents '°j°é¦UÓ¥´¶}ªº¤åÀÉ
- Doc.Close False 'Ãö³¬¤åÀɨ䣫O¦s(ª`:·Q«O¦sªº¸Ü,±N«á±ªº°Ñ¼Æ§ï¬°True)
- Next Doc
- End If
- End If
- .Quit 'Ãö³¬·í«eªºword¶iµ{ <<<<<<³oÃä¦pªGF8°õ¦æ¡A¬O¥i¥H¦¨¥\Ãö³¬¤u§@ºÞ²zû¤¤ªºWORD.EXEªº
- End With
- Set WordApp = GetObject(, "word.application") 'Àò¨ú¤U¤@Óword¶iµ{
- Loop
- Skip:
- Set Doc = Nothing 'µ²§ô©Î¥X¿ù¸õÂà¦Ü¦¹,²MªÅÅܼƱM®×
- Set WordApp = Nothing
- '================================
- Dim wdObj As Object
- Dim strXls As String, strSQL As String
- Dim a, b
- a = ThisWorkbook.Path '¦¹EXCELÀɮצs©ñ¦ì¸m
- b = ThisWorkbook.Name 'b¬°ÀɦW
- strXls = a & "\" & b '¦¹EXCELÀɮק¹¾ã¸ô®|¤ÎÀɦW
- Set wdObj = CreateObject("Word.Application") '·|¥ý§â©Ò¦³WORD³£Ãö±¼¡A©Ò¥H¥ÎCreat ¤£¥ÎGet
- Set wdObj = New Word.Application '±Ò°ÊWord
- wdObj.Visible = True
- wdObj.Documents.Open (a & "\¦C¦L.docx")
- With wdObj '¨Ï¥ÎWith«á´N¥¿±`¤F
- '³oÃä¥H¤U¬O¥ÎWORD¿ý»s¥¨¶°±o¨ìªº¦X¨Ö¦C¦L¼gªk
- .ActiveDocument.MailMerge.OpenDataSource Name:= _
- strXls, ConfirmConversions:=False, _
- ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
- PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
- WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
- Connection:= _
- "Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=strXls;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=37;Jet OLEDB:Database Locki" _
- , SQLStatement:="SELECT * FROM `¤u§@ªí1", SQLStatement1:="", SubType:= _
- wdMergeSubTypeAccess
-
- .ActiveDocument.MailMerge.Fields.Add Range:=.ActiveDocument.Tables(1).Cell(2, 1).Range, Name:="¸¹½X"
-
- .CommandBars("Mail Merge Panes").Visible = False
-
- With .ActiveDocument.MailMerge
- .Destination = wdSendToNewDocument
- .SuppressBlankLines = True
- With .DataSource
- .FirstRecord = wdDefaultFirstRecord
- .LastRecord = wdDefaultLastRecord
- End With
- .Execute Pause:=False
- End With
-
- End With
- Set wdObj = Nothing
- MsgBox ("¦C¦L«á¡AÃö³¬WORDÀɮ׮ɡA°O±o³q³q¡i¤£nÀx¦s¡j")
- MsgBox ("³Ì«á¤£¦L¤F¡A°O±o°õ¦æ¡i²M°£I´ºWORDµ{¦¡¡j")
- End Sub
½Æ»s¥N½X ¨D±Ï¦U¦ì¡AÁÂÁÂ
¦X¨Ö¦C¦L´ú¸Õ.rar (34.5 KB)
|
|