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

[¤À¨É] VBA-¤@¦¸§ó·s§AWORD¸Ì­±¡A©Ò¦³³s°ÊEXCELÀx¦s®æ³sµ²!

[¤À¨É] VBA-¤@¦¸§ó·s§AWORD¸Ì­±¡A©Ò¦³³s°ÊEXCELÀx¦s®æ³sµ²!

¤p§Ì°µ³ø§i®Ñªº²ßºD´N°¾¦n³s°ÊEXCEL¸Ì­±¯S©wÀx¦s®æ¡C
¨Ò¦p
{ LINK Excel.SheetMacroEnabled.12 "D:\\®×¥ó\\¶}µo®×\\¤ô²z­pºâ.xlsm" ªì´Á³]©w!R4C4 \t }

ê©ó¸Ì­±¦³¦s¦b«Ü¦h³sµ²¨ì§OªºWORD®ÑÅÒ¡A¾É­P³Ì¦­°µªk³£¬O¦b"ÀÉ®×"->"¸ê°T"->"½s¿èÀɮ׳sµ²" ºCºC§ï

©Ò¥H¤Wºô§ä¤F¥H¤UªºCODE
  1. Public Sub changeSource()
  2. Dim dlgSelectFile As FileDialog 'FileDialog object '
  3. Dim thisField As Field
  4. Dim selectedFile As Variant
  5. 'must be Variant to contain filepath of selected item
  6. Dim newFile As Variant
  7. Dim fieldCount As Integer '
  8. Dim x As Long
  9. On Error GoTo LinkError
  10. 'create FileDialog object as File Picker dialog box
  11. Set dlgSelectFile = Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
  12. With dlgSelectFile
  13.    .Filters.Clear 'clear filters
  14.   .Filters.Add "Microsoft Excel Files", "*.xls, *.xlsb, *.xlsm, *.xlsx" 'filter for o    nly Excel files
  15.   'use Show method to display File Picker dialog box and return user's action
  16.   If .Show = -1 Then
  17. 'step through each string in the FileDialogSelectedItems collection
  18.     For Each selectedFile In .SelectedItems
  19.          newFile = selectedFile 'gets new filepath
  20.        Next selectedFile
  21.      Else 'user clicked cancel
  22.    Exit Sub
  23.   End If
  24. End With
  25. Set dlgSelectFile = Nothing
  26. 'update fields
  27. With ActiveDocument
  28.   fieldCount = .Fields.Count
  29.   For x = 1 To fieldCount
  30.     With .Fields(x)
  31.      'Debug.Print x '
  32.      Debug.Print .Type
  33.       If .Type = 56 Then
  34.         'only update Excel links. Type 56 is an excel link
  35.         .LinkFormat.SourceFullName = newFile '
  36.         .Update
  37.         .LinkFormat.AutoUpdate = False
  38.         DoEvents
  39.       End If
  40.     End With
  41.   Next x
  42. End With
  43. MsgBox "¡I§ó·s§¹¦¨¡I"
  44. Exit Sub
  45. LinkError:
  46. Select Case Err.Number
  47.   Case 5391 'could not find associated Range Name
  48.     MsgBox "Could not find the associated Excel Range Name " & _
  49.       "for one or more links in this document. " & _
  50.       "Please be sure that you have selected a valid " & _
  51.       "Quote Submission input file.", vbCritical
  52.       Case Else
  53.         MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical
  54.     End Select
  55. End Sub
½Æ»s¥N½X
For x = 1 To fieldCount
¦b³o¸Ì§Ú¬O·|§ï¦¨ 1 To 25¡A¤£½T©w³o¤°»ò·N«ä....«¢
°_ªì§Ú¤å¥ó¤º¦³100¦h­¶¡A¥i¯à¨C10­¶´N·|¦³­ÓEXCEL³sµ²¡A¾É­P¦A¨ê·s®É...·|µ¥«Ü¤[...
©Ò¥H§Ú«á¨Óªº§@ªk´N¬O¦b²Ä¤@­¶³]©wªí®æ¨Ã¥[¤J®ÑÅÒ¡A¸Ì­±³£¬OEXCEL³sµ²¡A°²³]¸Ì­±¦³25­Ó¬O³sµ²excelªº....
¦n¹³´N¯uªº·|Ū¨ú³o25­Ó....´N·|¶]¤ñ¸û§Ö

¥t¥~§Ú¦³¦Ó¥~³]©w¡A¨C¦¸¶}±ÒWORD ´N·|°õ¦æ³o¥N½X
  1. Sub Document_Open()  
  2. changeSource
  3. End Sub
½Æ»s¥N½X
¥t¥~¦A¤À¨É¤@­Ó¦n¡A¦pªG§A·Q­n°Ñ¦Ò§OªºWORDÀɮתº¤º®e¡A¨Ò¦pAÀɮ׳sµ²BÀɮסA¥i¥H¥ý¦bBÀɮ׸̭±¡A§A·Q­nªº¤å¦r³]©w®ÑÅÒ
¨Ò¦p ³Â»¶®a±Ú°Q½×ª©
¦¹®É§A¥i¥H¦bAÀɮסG
¼ÐÃD¡G³Â»¶®a±Ú°Q½×ª©
{ INCLUDETEXT  " {FILENAME \p}\\..\\"BÀÉ®×" "³Â»¶®a±Ú°Q½×ª©" \* MERGEFORMAT }
{}ÃC¦â¯»¦â³o­Ó¡A¤@©w­n¥Îctrl+p®@!!!

³o¼Ë¤£ºÞ§A©ñ¦b­þ¸Ì¡A³£¤£·|¥X²{¿ù»~ÂP¡A¥u¬O³o¨â­ÓÀɮפ@©w­n©ñ¦b®Ç®@

½Ð°Ý¥i¥H¦³ªþÀɶÜ

TOP

Desktop.zip (46.63 KB)

§A¦b¸Õ¥Î¬Ý¬ÝÂP

TOP

        ÀR«ä¦Û¦b : ªY½à§O¤H´N¬O²øÄY¦Û¤v¡C
ªð¦^¦Cªí ¤W¤@¥DÃD