ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¦p¦ó¨Ï¥ÎVBA±NEXCLE¦C¥Xªº²M³æÂনWORD

[µo°Ý] ¦p¦ó¨Ï¥ÎVBA±NEXCLE¦C¥Xªº²M³æÂনWORD

¦U¦ì¤j¤j:
½Ð°Ý¤@¤UVBA¦³¥\¯à±Nªþ¥óªºExcle°O¿ý¤ºªº¸ê®Æ Âনword¶Ü?
¥B¥t¥~¦b²M³æªº­¶­±¦b¬ö¿ýÂনwordªº¸ê®Æ
Âà´««á°O¿ý­¶­±ªº¸ê®Æ²MªÅ

excle²M³æÂàword.zip (13.32 KB)

®v§Ú

¦^´_ 1# et010884
¸Õ¸Õ¬Ý
  1. Option Explicit
  2. Sub µ²§ô¶×¥X()
  3.     Dim Rng As Range
  4.     Set Rng = Sheets("¬ö¿ý").[A2]
  5.     With CreateObject("Word.APPLICATION")
  6.         .Visible = True
  7.         .Documents.Open ("§¹¾ãªº¸ô®|ÀɮצWºÙ.doc")
  8.         With .ActiveDocument.Tables(1)  'WordÀɮפ¤²Ä¤@­Óªí®æ
  9.          .Cell(1, 1) = Rng(1, 1) '©m¦W
  10.          .Cell(1, 2) = Rng(1, 2) '½s¸¹
  11.          .Cell(1, 3) = Rng(1, 3) '³¡ªù
  12.          '.Cell(?, ?)= ¾ºÙ ,¦~¸ê , ¬ö¿ý, ­±½ÍªÌ:¾l¤U¸ê®Æ½Ð¦Û¦æ¶ñ¤J
  13.         End With
  14.         .ActiveDocument.Close True
  15.         .Quit
  16.     End With
  17.     Rng.Resize(1, 7) = "" 'Âà´««á°O¿ý­¶­±ªº¸ê®Æ²MªÅ
  18. End Sub
½Æ»s¥N½X

TOP

¦^´_ 2# GBKEE


    GBKEE ¤j¤j: ÁÂÁ§A ¦b½Ð°Ý¤@¤U §Úªº®æ¦¡¦pªG¬O¦X¨ÖÀx¦s®æ®É ­n¦p¦ó´«®æ
®v§Ú

TOP

¦^´_ 2# GBKEE

GBKEE¤j¤j:
¤p§ÌÁÙ¦³´X­Ó°ÝÃD,½Ð§AÀ°¦£¸Ñµª
1.§Æ±æ¦³¥t¦s·sÀɪº¥\¯à=WORD¶×¥X®É
2.¬ö¿ý¶}³æ¶×¥X¤À­¶¦p§¹¦¨¶×¥X«h¬ö¿ý¦b¶}³æ¬ö¿ý²M³æ¦ý­«½Æ¶}³æªº¤£¬ö¿ý
3.·Q¦b¶}³æ¬ö¿ý²M³æ¿ï¾Ü¤w¶}¹Lªº²M³æ¦A¶}¥ß¤@¦¸
4. WordÀÉ ¤å¥ó½s¸¹¨º¤@Äæ¦ì«°¥«­n«ç»ò¼g
½Ð¦bÀ°À°¦£
ÁÂÁÂ

·s¼W¸ê®Æ§¨ (2).zip (20.29 KB)

®v§Ú

TOP

¦^´_ 4# et010884
¤u§@ªí ªº [¶µ¦¸] WORDªº.DOC  ¨S¨£¨ì :½Ð»¡©ú«á¦A°µ ¬ö¿ý,²M³æªºµ{§Ç
¦p­n­«µo: ¤wµo¥X¤§¬ö¿ý:½Ð¦b[²M³æ]¤u§@ªí¥ý°µ¤@¨Ç¬ö¿ý½d¨Ò
  1. Option Explicit
  2. Sub µ²§ô¶×¥X()
  3.     Dim RNG As Range, ss As Object
  4.     Set RNG = Sheets("¬ö¿ý").[A2]
  5.     With CreateObject("Word.APPLICATION")
  6.         .Visible = True
  7.         .Documents.Open (ThisWorkbook.Path & "\1.doc")
  8.         Set ss = .ActiveDocument.Sentences(1)
  9.         
  10.         '*** Word VBA:  Sentences ¶°¦Xª«¥ó ½Ð°Ñ¾\Äݩʤèªk¨Æ¥ó¯S©w¦h­«ª«¥ó
  11.         '³o¬O¥Ñ Range ª«¥ó©Ò²Õ¦¨ªº¶°¦X¡A¥Nªí¿ï¨ú½d³ò¡B½d³ò©Î¤å¥ó¤¤ªº©Ò¦³¥y¤l¡C¨S¦³©Ò¿× Sentence ª«¥ó¡C

  12.         .ActiveDocument.Range(InStr(ss, "¡G"), Len(ss) - 1) = RNG(1, 2)
  13.         '¤å¥ó½s¸¹
  14.         With .ActiveDocument.Tables(1)  'WordÀɮפ¤²Ä¤@­Óªí®æ
  15.         ' .Cell(2, 1) = Rng(1, 1) '¶µ¦¸  '*** ²M³æªº­þ¤@¶µ***
  16.          .Cell(2, 2) = RNG(1, 3) 'µo¦æ¤é´Á
  17.          .Cell(2, 3) = RNG(1, 4) 'Product code
  18.          .Cell(2, 4) = RNG(1, 5) '«È¤á
  19.          .Cell(2, 5) = RNG(1, 6) 'Product code
  20.          .Cell(2, 6) = RNG(1, 7) 'Lot id
  21.          .Cell(2, 7) = RNG(1, 8) 'line
  22.         .Cell(2, 8) = RNG(1, 9) 'Qty
  23.          .Cell(4, 2) = RNG(1, 10) '¤º®e
  24.          .Cell(5, 3) = RNG(1, 11) '¦¬¥ó¤é´Á
  25.          .Cell(5, 7) = RNG(1, 12) '®Ö¹ï¤H
  26.           .Cell(9, 4) = RNG(1, 13) 'Detail Explain
  27.          '.Cell(?, ?)= ¾ºÙ ,¦~¸ê , ¬ö¿ý, ­±½ÍªÌ:¾l¤U¸ê®Æ½Ð¦Û¦æ¶ñ¤J
  28.         End With
  29.          .ActiveDocument.SaveAs Filename:="D:\OK.doc"  '*** WORD¶×¥X ***
  30.          '.ActiveDocument.Close True
  31.         .Quit
  32.     End With
  33.    
  34.     'Rng.Resize(1, 13) = "" 'Âà´««á°O¿ý­¶­±ªº¸ê®Æ²MªÅ
  35. End Sub
½Æ»s¥N½X

TOP

¦^´_ 5# GBKEE


    GBKEE¤j¤j
¤w¸É¤W»¡©ú
²M³æªº¤À­¶¬°¾ú¥v¬ö¿ý,¦p­n¶×¥X¾ú¥v¬ö¿ý¥u»Ý­n°Ï¿ï½d³ò«á«ö½Æ»s§Y¥iÂà¨ì¬ö¿ý­¶­±
¥t¥~¦p­n¥Ñ¬ö¿ý¤À­¶·s¼W²M³æ®É«h¥Ñ¤À­¶ªº¥t¤@­Ó«ö¶s°õ¦æ·s¼Wªº°Ê§@

³Ì«áÁÂÁ§A ¤j¤Oªº¨ó§U

EXCELÂàWORD.zip (46.82 KB)

®v§Ú

TOP

¦^´_ 6# et010884
  1. Option Explicit
  2. Dim WordÀÉ As String   '¶×¥XwordÀÉ,¦sÀɪº¦WºÙ
  3. Dim ¬ö¿ý As Range
  4. Sub ¶×¥Xword() '¥Ñ²M³æ½Æ»s«á¶×¥XwordÀÉ
  5.     Set ¬ö¿ý = Sheets("¬ö¿ý").[c2:m2]
  6.    MsgBox Application.CountA(¬ö¿ý)
  7.     If Application.CountA(¬ö¿ý) <> 11 Then
  8.         MsgBox "¸ê®Æ¤£»ô¥þ": Exit Sub
  9.     Else
  10.          Do
  11.          WordÀÉ = Application.InputBox("*.doc", "¶×¥XwordÀÉ,¦sÀɪº¦WºÙ")
  12.          Loop While WordÀÉ = "False" Or WordÀÉ = ""
  13.          If Not InStr(LCase(WordÀÉ), "*.doc") Then WordÀÉ = WordÀÉ & ".doc"
  14.     End If
  15.     Main
  16.     ²M³æÀˬd
  17. End Sub
  18. Sub ²M³æÀˬd()   'Àˬd¬ö¿ý¤£¦s¦b: ¸ß°Ý¬O§_¥[¤J
  19.     Dim R As Integer, E As Range, MM As String
  20.     Set ¬ö¿ý = Sheets("¬ö¿ý").[c2:m2]
  21.     With Sheets("²M³æ")
  22.         R = .Cells(.Rows.Count, "c").End(xlUp).Row   '²M³æ:¬ö¿ýªº¦C¼Æ
  23.         If R = 1 Then
  24.             GoTo OK
  25.         Else
  26.             MM = Join(Application.Transpose(Application.Transpose(¬ö¿ý.Value)), vbLf)
  27.             For Each E In .Range("C2:M2").Resize(R - 1).Rows
  28.                 If MM = Join(Application.Transpose(Application.Transpose(E.Value)), vbLf) Then GoTo EE
  29.             Next
  30.         End If
  31. OK:
  32.         If MsgBox(MM, vbYesNo, "°O¿ý: ¦s¤J²M³æ..") = vbYes Then
  33.             ¬ö¿ý.Copy .Cells(R + 1, "c")                 '½Æ»s¨ì¬ö¿ýªº¦C¼Æ+1
  34.             .Cells(R + 1, "B").NumberFormatLocal = "@"
  35.             .Cells(R + 1, "B").FormulaR1C1 = Format(R + 1, "000")
  36.         End If
  37. EE:
  38.         ¬ö¿ý.EntireRow = ""          'Âà´««á°O¿ý­¶­±ªº¸ê®Æ²MªÅ
  39.     End With
  40. End Sub
  41. Sub ½Æ»s¨ì¬ö¿ý()
  42.     Dim Rng As Range
  43.     With Sheets("²M³æ")
  44.           Set Rng = .Range("a1").CurrentRegion.Rows(2)
  45.           Set Rng = Rng.Resize(.Range("a1").CurrentRegion.Rows.Count - 1)
  46.             If Not Application.Intersect(Rng, ActiveCell) Is Nothing Then
  47.                 .Range("A" & ActiveCell.Row & ":" & "M" & ActiveCell.Row).Copy Sheets("¬ö¿ý").Range("A2")
  48.                 MsgBox "½s¸¹: " & vbTab & "[" & .Range("B" & ActiveCell.Row) & "]", , "½Æ»s¨ì¬ö¿ý!!"
  49.             Else
  50.                 MsgBox "»Ý¿ï¾Ü¦b ²M³æªº½d³ò"
  51.                 Rng.Select
  52.             End If
  53.         End With
  54. End Sub
  55. Private Sub Main()                 '°O¿ý¶×¥X¨ìwordÀÉ
  56.     With CreateObject("Word.APPLICATION")
  57.         .Visible = True
  58.        ' .Documents.Open ("\\Tctk0fi25\oqa_report$\04_²§±`³B²zªí³æ_R3\¤£¦X®æ³æ¶}¥ß°Ï\1.doc")
  59.        .Documents.Open (ThisWorkbook.Path & "\1.doc")
  60.         With .ActiveDocument.Tables(1)  'WordÀɮפ¤²Ä¤@­Óªí®æ
  61.         ' .Cell(2, 1) = Rng(1, 1) '¶µ¦¸
  62.          '.Cell(2, 2) = Rng(1, 2) '½s¸¹
  63.          .Cell(2, 2) = ¬ö¿ý(1, 1) 'µo¦æ¤é´Á
  64.          .Cell(2, 3) = ¬ö¿ý(1, 2) 'Product code
  65.          .Cell(2, 4) = ¬ö¿ý(1, 3) '«È¤á
  66.          .Cell(2, 5) = ¬ö¿ý(1, 4) 'Product code
  67.          .Cell(2, 6) = ¬ö¿ý(1, 5) 'Lot id
  68.          .Cell(2, 7) = ¬ö¿ý(1, 6) 'line
  69.         .Cell(2, 8) = ¬ö¿ý(1, 7) 'Qty
  70.          .Cell(4, 2) = ¬ö¿ý(1, 8) '¤º®e
  71.          .Cell(5, 3) = ¬ö¿ý(1, 9) '¦¬¥ó¤é´Á
  72.          .Cell(5, 7) = ¬ö¿ý(1, 10) '®Ö¹ï¤H
  73.           .Cell(9, 4) = ¬ö¿ý(1, 11) 'Detail Explain
  74.          '.Cell(?, ?)= ¾ºÙ ,¦~¸ê , ¬ö¿ý, ­±½ÍªÌ:¾l¤U¸ê®Æ½Ð¦Û¦æ¶ñ¤J
  75.         End With
  76.            .ActiveDocument.SaveAs Filename:="D:\TEST\" & WordÀÉ '*** WORD¶×¥X ***
  77.            .ActiveDocument.Close                                    'Ãö³¬wordÀÉ 'True
  78.         .Quit                                                       'Ãö³¬wordÀ³¥Îµ{¦¡
  79.     End With   
  80. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : §Ú­Ì­n°µ¦nªÀ·|ªºÀô«O¡A¤]­n°µ¦n¤º¤ßªºÀô«O¡C
ªð¦^¦Cªí ¤W¤@¥DÃD